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";