Skip Menu |

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

Report information
The Basics
Id: 28916
Status: open
Priority: 0/
Queue: Perl-MinimumVersion

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

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Additional syntax checks (code included)
I've added checks for most of the version dependencies I tend to care about. Add to %CHECKS _four_arg_substr => version->new('5.005'), _negative_splice_length => version->new('5.005'), _three_arg_open => version->new('5.006'), _autovivified_filehandles => version->new('5.006'), _exists_sub => version->new('5.006'), _exists_delete_array => version->new('5.006'), _binary_printf_format => version->new('5.006'), _sortsub_coderef => version->new('5.006'), _CHECK_blocks => version->new('5.006'), _in_memory_file => version->new('5.008'), _anonymous_temp_file => version->new('5.008'), _UNTIE_method => version->new('5.008'), _SCALAR_method => version->new('5.008.003'), Subroutines: sub _four_arg_substr { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'substr' and $_[1]->snext_sibling->child(0)->schildren > 5; }); } sub _negative_splice_length { shift->Document->find_any(sub { return 0 unless ($_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'splice'); my $expr = $_[1]->snext_sibling->child(0)->schild(4); return $expr ? $expr->content < 0 : 0; }); } sub _three_arg_open { shift->Document->find_any(sub { return 0 unless $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'open'; my $n = grep { $_->isa('PPI::Token::Operator') && ( $_->content eq ',' || $_->content eq '=>') } $_[1]->snext_sibling->child(0)->schildren; return $n > 1; }); } sub _autovivified_filehandles { # TODO: figure out how (and if) this is applicable to socketpair, socket, # and accept shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content =~ /^(?:open|opendir|sysopen)$/ and $_[1]->snext_sibling->schild(0)->isa('PPI::Statement::Variable'); }); } sub _exists_sub { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'exists' and $_[1]->snext_sibling->find_first('PPI::Token::Symbol')->symbol_type eq '&'; }); } sub _exists_delete_array { shift->Document->find_any(sub { return 0 unless $_[1]->isa('PPI::Token::Word') and ($_[1]->content eq 'exists' or $_[1]->content eq 'delete'); my $expr = $_[1]->snext_sibling->find_first('PPI::Structure::Subscript'); return $expr ? $expr->start->content eq '[' : 0; }); } # This might be overzealous. It looks for binary formats in *any* string to # catch cases like this: # my $fmt = "%b"; # printf($fmt, 10); # But it's possible that C<$fmt> is never used as a s?printf() format string. sub _binary_printf_format { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Quote') and $_[1]->content =~ /%-?(?:\d|.\d)\d*(?:\.\d*)?b/; }); } sub _sortsub_coderef { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'sort' and $_[1]->snext_sibling->isa('PPI::Token::Symbol'); }); } sub _CHECK_blocks { shift->Document->find_any( sub { $_[1]->isa('PPI::Statement::Scheduled') and $_[1]->type eq 'CHECK' } ); } sub _in_memory_file { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'open' and $_[1]->snext_sibling->find_any('PPI::Token::Cast'); }); } sub _anonymous_temp_file { shift->Document->find_any(sub { return 0 unless $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'open'; my $token = $_[1]->snext_sibling->find_first('PPI::Token::Word'); return $token ? $token->content eq 'undef' : 0; }); } sub _UNTIE_method { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'UNTIE'; }); } sub _SCALAR_method { shift->Document->find_any(sub { $_[1]->isa('PPI::Token::Word') and $_[1]->content eq 'SCALAR'; }); }
Subject: Re: [rt.cpan.org #28916] Additional syntax checks (code included)
Date: Tue, 21 Aug 2007 22:45:53 +1000
To: bug-Perl-MinimumVersion [...] rt.cpan.org
From: "Adam Kennedy" <adamkennedybackup [...] gmail.com>
Thanks for these Michael I did a quick scan through, about half I'll add as soon as I can find a time slice to, and the other half I'll probably want to do a little refining to your implementationw (there's some there I suspect a few might generate false positive matches a bit too easily) Adam K On 8/21/07, Michael Carman via RT <bug-Perl-MinimumVersion@rt.cpan.org> wrote: Show quoted text
> > > Mon Aug 20 14:42:31 2007: Request 28916 was acted upon. > Transaction: Ticket created by MJCARMAN > Queue: Perl-MinimumVersion > Subject: Additional syntax checks (code included) > Broken in: (no value) > Severity: Wishlist > Owner: Nobody > Requestors: mjcarman@mchsi.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=28916 > > > > I've added checks for most of the version dependencies I tend to care > about. > > Add to %CHECKS > _four_arg_substr => version->new('5.005'), > _negative_splice_length => version->new('5.005'), > _three_arg_open => version->new('5.006'), > _autovivified_filehandles => version->new('5.006'), > _exists_sub => version->new('5.006'), > _exists_delete_array => version->new('5.006'), > _binary_printf_format => version->new('5.006'), > _sortsub_coderef => version->new('5.006'), > _CHECK_blocks => version->new('5.006'), > _in_memory_file => version->new('5.008'), > _anonymous_temp_file => version->new('5.008'), > _UNTIE_method => version->new('5.008'), > _SCALAR_method => version->new('5.008.003'), > > Subroutines: > sub _four_arg_substr { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'substr' and > $_[1]->snext_sibling->child(0)->schildren > 5; > }); > } > > sub _negative_splice_length { > shift->Document->find_any(sub { > return 0 unless ($_[1]->isa('PPI::Token::Word') > and $_[1]->content eq > 'splice'); > my $expr = > $_[1]->snext_sibling->child(0)->schild(4); > return $expr ? $expr->content < 0 : 0; > }); > } > > sub _three_arg_open { > shift->Document->find_any(sub { > return 0 unless $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq > 'open'; > > my $n = grep { > $_->isa('PPI::Token::Operator') && > ( $_->content eq ',' || $_->content eq > '=>') > } $_[1]->snext_sibling->child(0)->schildren; > > return $n > 1; > }); > } > > sub _autovivified_filehandles { > # TODO: figure out how (and if) this is applicable to > socketpair, socket, > # and accept > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content =~ /^(?:open|opendir|sysopen)$/ and > > $_[1]->snext_sibling->schild(0)->isa('PPI::Statement::Variable'); > }); > } > > sub _exists_sub { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'exists' and > > $_[1]->snext_sibling->find_first('PPI::Token::Symbol')->symbol_type > eq '&'; > }); > } > > sub _exists_delete_array { > shift->Document->find_any(sub { > return 0 unless $_[1]->isa('PPI::Token::Word') and > ($_[1]->content eq 'exists' or > $_[1]->content eq 'delete'); > my $expr = > $_[1]->snext_sibling->find_first('PPI::Structure::Subscript'); > return $expr ? $expr->start->content eq '[' : 0; > }); > } > > # This might be overzealous. It looks for binary formats in *any* > string to > # catch cases like this: > # my $fmt = "%b"; > # printf($fmt, 10); > # But it's possible that C<$fmt> is never used as a s?printf() > format > string. > sub _binary_printf_format { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Quote') and > $_[1]->content =~ /%-?(?:\d|.\d)\d*(?:\.\d*)?b/; > }); > } > > sub _sortsub_coderef { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'sort' and > $_[1]->snext_sibling->isa('PPI::Token::Symbol'); > }); > } > > sub _CHECK_blocks { > shift->Document->find_any( sub { > $_[1]->isa('PPI::Statement::Scheduled') and > $_[1]->type eq 'CHECK' > } ); > } > > > sub _in_memory_file { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'open' and > > $_[1]->snext_sibling->find_any('PPI::Token::Cast'); > }); > } > > sub _anonymous_temp_file { > shift->Document->find_any(sub { > return 0 unless $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq > 'open'; > my $token = > $_[1]->snext_sibling->find_first('PPI::Token::Word'); > return $token ? $token->content eq 'undef' : 0; > }); > } > > sub _UNTIE_method { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'UNTIE'; > }); > } > > sub _SCALAR_method { > shift->Document->find_any(sub { > $_[1]->isa('PPI::Token::Word') and > $_[1]->content eq 'SCALAR'; > }); > } > >

Message body is not shown because it is too large.

Subject: Re: [rt.cpan.org #28916] Additional syntax checks (code included)
Date: Tue, 21 Aug 2007 13:35:57 +0000
To: bug-Perl-MinimumVersion [...] rt.cpan.org
From: mjcarman [...] mchsi.com (Michael Carman)
From: "Adam Kennedy via RT" <bug-Perl-MinimumVersion@rt.cpan.org> Show quoted text
> > Thanks for these Michael
You're welcome. Show quoted text
> I'll probably want to do a little refining to your implementation > (there's some there I suspect a few might generate false positive > matches a bit too easily)
I'm a PPI novice so that's very possible. I did my debug testing against typical cases. I think it's best to cover them first (to make the module more complete and useful) and to worry about the atypical cases later. Have you given any consideration to the DAGOLDEN's request for verbose output? I think it's a great idea for people trying to write backwards-compatible code (although admittedly it would have a significant impact on the architecture and performance). -mjc
On Tue Aug 21 05:46:53 2007, adamkennedybackup@gmail.com wrote: Show quoted text
> Thanks for these Michael > > I did a quick scan through, about half I'll add as soon as I can find > a time > slice to
Did these make it in?