Skip Menu |

This queue is for tickets about the PPI-PowerToys CPAN distribution.

Report information
The Basics
Id: 27147
Status: open
Priority: 0/
Queue: PPI-PowerToys

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

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



Subject: ppi_version doesn't work with $VERSION as unquoted number
Attached please find a patch to fix a blindspot in ppi_version, which doesn't work if you use $VERSION = 0.2301; (still the recommended mode), instead of $VERSION = '0.2301'; which _isn't_ equivalent. This patch isn't sufficient when someone does this: use version; $VERSION = qv("0.0.1"); I'll try and add that (once I learn a little more about PPI)... John
Subject: ppi_version.patch
--- /usr/bin/ppi_version 2007-05-15 21:55:47.000000000 -0400 +++ /tmp/ppi_version 2007-05-15 22:53:51.000000000 -0400 @@ -27,9 +27,6 @@ unless ( $to and $to =~ /^[\d\._]+$/ ) { die "To is not a number"; } -$from = "'$from'"; -$to = "'$to'"; - # Find all modules and scripts below the current directory my @files = File::Find::Rule->file ->name('*.pm', '*.pl', '*.t') @@ -61,8 +58,9 @@ sub changefile { # Does the document contain a simple version number my $elements = $Document->find( sub { - $_[1]->isa('PPI::Token::Quote') or return ''; - $_[1]->content eq $from or return ''; + $_[1]->isa('PPI::Token::Quote') or + $_[1]->isa('PPI::Token::Number') or return ''; + $_[1]->content =~ /$from/ or return ''; my $equals = $_[1]->sprevious_sibling or return ''; $equals->isa('PPI::Token::Operator') or return ''; $equals->content eq '=' or return ''; @@ -76,7 +74,7 @@ sub changefile { die "$file contains more than one $VERSION = '$from';"; } my $element = $elements->[0]; - $element->{content} = $to; + $element->{content} =~ s/$from/$to/; # Save the updated version $Document->save( $file ) or die "PPI::Document save failed";
OK, the attached patch should be used instead of the previous one, and covers the following [common] $VERSION assignments: $VERSION = 0.100; $VERSION = '0.100'; $Some::Module::VERSION = 0.100; $Some::Module::VERSION = '0.100'; use version; $VERSION = version->new(0.100); use version; $VERSION = version->new('0.100'); use version; $VERSION = version->new('0.1.0'); use version; $VERSION = version->new(0.1.0); # Perl > 5.8.1 use version; $VERSION = qv('0.1.0'); use version; $VERSION = qv(0.1.0); # Perl > 5.8.1 The only [rare] $VERSION assignment that the patch doesn't handle is the CVS style method (currently mentioned in perlmod): $VERSION = sprintf "%d.%03d", q$Revision: 1.1 $ =~ /(\d+)/g which isn't really a bad thing, since that is profoundly evil (as CVS increments branch revisions in a non-linear fashion), though that limitation should probably be mentioned in the POD. John
--- /usr/bin/ppi_version 2007-05-15 21:55:47.000000000 -0400 +++ ppi_version 2007-05-16 11:05:16.000000000 -0400 @@ -27,9 +27,6 @@ unless ( $to and $to =~ /^[\d\._]+$/ ) { die "To is not a number"; } -$from = "'$from'"; -$to = "'$to'"; - # Find all modules and scripts below the current directory my @files = File::Find::Rule->file ->name('*.pm', '*.pl', '*.t') @@ -61,14 +58,28 @@ sub changefile { # Does the document contain a simple version number my $elements = $Document->find( sub { - $_[1]->isa('PPI::Token::Quote') or return ''; - $_[1]->content eq $from or return ''; - my $equals = $_[1]->sprevious_sibling or return ''; - $equals->isa('PPI::Token::Operator') or return ''; - $equals->content eq '=' or return ''; - my $version = $equals->sprevious_sibling or return ''; - $version->isa('PPI::Token::Symbol') or return ''; - $version->content eq '$VERSION' or return ''; + $_[1]->isa('PPI::Token::Quote') or + $_[1]->isa('PPI::Token::Number') or return ''; + $_[1]->content =~ /$from/ or return ''; + my $equals = $_[1]->sprevious_sibling; + if ( $equals ) { + $equals->isa('PPI::Token::Operator') or return ''; + $equals->content eq '=' or return ''; + my $version = $equals->sprevious_sibling or return ''; + $version->isa('PPI::Token::Symbol') or return ''; + $version->content =~ /^\$.*VERSION$/ or return ''; + } + else { + my $ggparent = $_[1]->parent->parent->parent + or return ''; + my ($version) = $ggparent->children or return ''; + $version->isa('PPI::Token::Symbol') or return ''; + $version->content =~ /^\$.*VERSION$/ or return ''; + $equals = $version->snext_sibling or return ''; + $equals->isa('PPI::Token::Operator') or return ''; + $equals->content eq '=' or return ''; + } + 1; } ); return '' unless $elements; @@ -76,7 +87,7 @@ sub changefile { die "$file contains more than one $VERSION = '$from';"; } my $element = $elements->[0]; - $element->{content} = $to; + $element->{content} =~ s/$from/$to/; # Save the updated version $Document->save( $file ) or die "PPI::Document save failed";