Skip to content

Commit 456d56d

Browse files
committed
parse version v0.9_9 correctly
1 parent 0556b37 commit 456d56d

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

lib/MetaCPAN/Util.pm

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package MetaCPAN::Util;
2-
32
# ABSTRACT: Helper functions for MetaCPAN
43
use strict;
54
use warnings;
@@ -9,38 +8,45 @@ use Try::Tiny;
98
use Encode;
109

1110
sub digest {
12-
my $digest = Digest::SHA1::sha1_base64( join( "\0", grep {defined} @_ ) );
11+
my $digest = Digest::SHA1::sha1_base64(join("\0", grep { defined } @_));
1312
$digest =~ tr/[+\/]/-_/;
1413
return $digest;
1514
}
1615

1716
sub numify_version {
1817
my $version = shift;
1918
use warnings FATAL => 'numeric';
20-
eval { $version = version->parse($version)->numify + 0; } or do {
19+
eval {
20+
$version = version->parse( $version )->numify+0;
21+
} or do {
2122
$version = fix_version($version);
22-
$version = eval { version->parse( $version || 0 )->numify + 0 };
23+
$version = eval { version->parse( $version || 0 )->numify+0 };
2324
};
2425
return $version;
2526
}
2627

2728
sub fix_version {
2829
my $version = shift;
29-
return undef unless ( defined $version );
30+
return undef unless(defined $version);
31+
if($version =~ /^v/) {
32+
eval { $version = eval(version->parse( $version )->numify) };
33+
return $version+0 unless($@);
34+
}
3035
$version =~ s/[^\d\._]//g;
3136
$version =~ s/_/00/g;
3237
return $version;
3338
}
3439

3540
sub author_dir {
3641
my $pauseid = shift;
37-
my $dir = 'id/'
38-
. sprintf( "%s/%s/%s",
39-
substr( $pauseid, 0, 1 ),
40-
substr( $pauseid, 0, 2 ), $pauseid );
42+
my $dir = 'id/'
43+
. sprintf( "%s/%s/%s",
44+
substr( $pauseid, 0, 1 ),
45+
substr( $pauseid, 0, 2 ), $pauseid );
4146
return $dir;
4247
}
4348

49+
4450
# TODO: E<escape>
4551
sub strip_pod {
4652
my $pod = shift;
@@ -51,48 +57,46 @@ sub strip_pod {
5157

5258
sub extract_section {
5359
my ( $pod, $section ) = @_;
54-
eval { $pod = Encode::decode_utf8( $pod, Encode::FB_CROAK ) };
60+
eval { $pod = Encode::decode_utf8($pod, Encode::FB_CROAK) };
5561
return undef
56-
unless ( $pod =~ /^=head1 $section\b(.*?)(^((\=head1)|(\=cut)))/msi
62+
unless ( $pod =~ /^=head1 $section\b(.*?)(^((\=head1)|(\=cut)))/msi
5763
|| $pod =~ /^=head1 $section\b(.*)/msi );
5864
my $out = $1;
5965
$out =~ s/^\s*//g;
6066
$out =~ s/\s*$//g;
6167
return $out;
6268
}
6369

70+
6471
sub pod_lines {
6572
my $content = shift;
66-
return [] unless ($content);
73+
return [] unless($content);
6774
my @lines = split( "\n", $content );
6875
my @return;
6976
my $count = 1;
7077
my $length = 0;
7178
my $start = 0;
72-
my $slop = 0;
79+
my $slop = 0;
7380
foreach my $line (@lines) {
74-
7581
if ( $line =~ /\A=cut/ ) {
7682
$length++;
7783
$slop++;
78-
push( @return, [ $start - 1, $length ] )
79-
if ( $start && $length );
84+
push( @return, [ $start-1, $length ] )
85+
if ( $start && $length );
8086
$start = $length = 0;
81-
}
82-
elsif ( $line =~ /\A=[a-zA-Z]/ && !$length ) {
87+
} elsif ( $line =~ /\A=[a-zA-Z]/ && !$length ) {
8388
$start = $count;
84-
}
85-
elsif ( $line =~ /\A\s*__DATA__/ ) {
89+
} elsif( $line =~ /\A\s*__DATA__/) {
8690
last;
8791
}
8892
if ($start) {
8993
$length++;
90-
$slop++ if ( $line =~ /\S/ );
94+
$slop++ if( $line =~ /\S/ );
9195
}
9296
$count++;
9397
}
94-
push( @return, [ $start - 1, $length ] )
95-
if ( $start && $length );
98+
push( @return, [ $start-1, $length ] )
99+
if ( $start && $length );
96100
return \@return, $slop;
97101
}
98102

t/util.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ is( MetaCPAN::Util::numify_version('0.20_8'), 0.208 );
1313
is( MetaCPAN::Util::numify_version('0.20_88'), 0.200088 );
1414
is( MetaCPAN::Util::numify_version('0.208_8'), 0.208008 );
1515
is( MetaCPAN::Util::numify_version('0.20_108'), 0.2000108 );
16+
is( MetaCPAN::Util::numify_version('v0.9_9'), 0.009009);
1617

1718
lives_ok { is( version("2a"), 2 ) };
1819
lives_ok { is( version("V0.01"), 0.01 ) };

0 commit comments

Comments
 (0)