Skip Menu |
 

This queue is for tickets about the Perl-MinimumVersion CPAN distribution.

Report information
The Basics
Id: 81140
Status: resolved
Priority: 0/
Queue: Perl-MinimumVersion

People
Owner: Nobody in particular
Requestors: YAKEX [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.28
Fixed in: 1.30



Subject: Argument of each, keys and values expanded in 5.12 and 5.14
Download (untitled) / with headers
text/plain 318b
each, keys and values accept ARRAY, such as @foo, in 5.12. ref. http://perldoc.perl.org/perl5123delta.html#keys%2c-values-work-on- arrays In 5.14, they accept SCALAR holding reference, also. ref. http://perldoc.perl.org/perl5140delta.html#Syntactical-Enhancements Attached patch adds syntactic detection and its test.
Subject: each_argument.patch
Download each_argument.patch
text/x-diff 3.2k
Index: lib/Perl/MinimumVersion.pm =================================================================== --- lib/Perl/MinimumVersion.pm (revision 15649) +++ lib/Perl/MinimumVersion.pm (working copy) @@ -109,7 +109,7 @@ _postfix_foreach => version->new('5.004.05'), ); @CHECKS_RV = ( #subs that return version - '_feature_bundle','_regex', + '_feature_bundle','_regex','_each_argument', ); # Predefine some indexes needed by various check methods @@ -575,6 +575,39 @@ return ($version, $obj); } +sub _each_argument { + my ($version, $obj); + shift->Document->find( sub { + $_[1]->isa('PPI::Token::Word') or return ''; + $_[1]->content =~ '^(each|keys|values)$' or return ''; + my $next = $_[1]->snext_sibling; + $next = $next->schild(0)->schild(0) if $next->isa('PPI::Structure::List'); + if($next->isa('PPI::Token::Cast')) { + if($next->content eq '@' && 5.012 > ($version || 0)) { + $version = 5.012; + $obj = $_[1]->parent; + } elsif($next->content eq '$' && 5.014 > ($version || 0)) { + $version = 5.014; + $obj = $_[1]->parent; + } + } elsif($next->isa('PPI::Token::Symbol')) { + if($next->raw_type eq '@' && 5.012 > ($version || 0)) { + $version = 5.012; + $obj = $_[1]->parent; + } elsif($next->raw_type eq '$' && 5.104 > ($version || 0)) { + $version = 5.014; + $obj = $_[1]->parent; + } + } else { # function call or other should be reference + if(5.014 > ($version || 0)) { + $version = 5.014; + $obj = $_[1]->parent; + } + } + } ); + return (defined($version)?"$version":undef, $obj); +} + sub _yada_yada_yada { shift->Document->find_first( sub { $_[1]->isa('PPI::Token::Operator') Index: t/14_each.t =================================================================== --- t/14_each.t (revision 0) +++ t/14_each.t (working copy) @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +#use version; +use Perl::MinimumVersion; +my %examples=( + q{each %foo} => undef, + q{each @foo} => 5.012, + q{each $ref} => 5.014, + q{each $ref->call} => 5.014, + q{each call()} => 5.014, + q{each(%foo)} => undef, + q{each(@foo)} => 5.012, + q{each($ref)} => 5.014, + q{each($ref->call)} => 5.014, + q{each(call())} => 5.014, + + q{keys %foo} => undef, + q{keys @foo} => 5.012, + q{keys $ref} => 5.014, + q{keys $ref->call} => 5.014, + q{keys call()} => 5.014, + q{keys(%foo)} => undef, + q{keys(@foo)} => 5.012, + q{keys($ref)} => 5.014, + q{keys($ref->call)} => 5.014, + q{keys(call())} => 5.014, + + q{values %foo} => undef, + q{values @foo} => 5.012, + q{values $ref} => 5.014, + q{values $ref->call} => 5.014, + q{values call()} => 5.014, + q{values(%foo)} => undef, + q{values(@foo)} => 5.012, + q{values($ref)} => 5.014, + q{values($ref->call)} => 5.014, + q{values(call())} => 5.014, +); +plan tests => scalar(keys %examples); +foreach my $example (sort keys %examples) { + my $p = Perl::MinimumVersion->new(\$example); + my ($v, $obj) = $p->_each_argument; + is( $v, $examples{$example}, $example ) + or do { diag "\$\@: $@" if $@ }; +}
Download (untitled) / with headers
text/plain 492b
On Tue Nov 13 11:43:39 2012, YAKEX wrote: Show quoted text
> each, keys and values accept ARRAY, such as @foo, in 5.12. > ref. http://perldoc.perl.org/perl5123delta.html#keys%2c-values-work-on- > arrays > In 5.14, they accept SCALAR holding reference, also. > ref. http://perldoc.perl.org/perl5140delta.html#Syntactical-Enhancements > > Attached patch adds syntactic detection and its test.
Added in 1.29 and patched in 1.30 to work correctly with 'each % { $foo }' -- Alexandr Ciornii, http://chorny.net


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.