| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Version::Compare; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Version::Compare::VERSION = '0.14'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Compare version strings |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
196410
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
69
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
649
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub max { |
|
12
|
8
|
|
|
8
|
1
|
11
|
my $x = shift; |
|
13
|
8
|
|
|
|
|
9
|
my $y = shift; |
|
14
|
8
|
100
|
|
|
|
32
|
return ( $x > $y ? $x : $y ); |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
## no critic(ProhibitNumberedNames ProhibitCStyleForLoops) |
|
18
|
|
|
|
|
|
|
sub version_compare { |
|
19
|
6
|
|
100
|
6
|
1
|
2962
|
my $ver1 = shift || 0; |
|
20
|
6
|
|
50
|
|
|
17
|
my $ver2 = shift || 0; |
|
21
|
6
|
|
|
|
|
27
|
my @v1 = split /[.+:~-]/, $ver1; |
|
22
|
6
|
|
|
|
|
24
|
my @v2 = split /[.+:~-]/, $ver2; |
|
23
|
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
19
|
for ( my $i = 0 ; $i < max( scalar(@v1), scalar(@v2) ) ; $i++ ) { |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Add missing version parts if one string is shorter than the other |
|
27
|
|
|
|
|
|
|
# i.e. 0 should be lt 0.2.1 and not equal, so we append .0 |
|
28
|
|
|
|
|
|
|
# -> 0.0.0 <=> 0.2.1 -> -1 |
|
29
|
8
|
50
|
|
|
|
19
|
push( @v1, 0 ) unless defined( $v1[$i] ); |
|
30
|
8
|
50
|
|
|
|
17
|
push( @v2, 0 ) unless defined( $v2[$i] ); |
|
31
|
8
|
100
|
|
|
|
36
|
if ( int( $v1[$i] ) > int( $v2[$i] ) ) { |
|
|
|
100
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
6
|
return 1; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
elsif ( int( $v1[$i] ) < int( $v2[$i] ) ) { |
|
35
|
5
|
|
|
|
|
30
|
return -1; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
0
|
|
|
|
|
|
return 0; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
## use critic |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
## no critic (RequireArgUnpacking ProhibitBuiltinHomonyms) |
|
43
|
|
|
|
|
|
|
sub cmp { |
|
44
|
0
|
|
|
0
|
1
|
|
return version_compare(@_); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
## use critic |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; # End of Version::Compare |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Version::Compare - Compare version strings |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 0.14 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use Version::Compare; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if(&Version::Compare::version_compare('2.6.26','2.6.0') == 1) { |
|
68
|
|
|
|
|
|
|
print "2.6.26 is greater than 2.6.0\n"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Version::Compare - Comparing version strings |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 max |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Return the bigger of the two numerical values |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 version_compare |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Compare two unix-style version strings like 2.6.23.1 and 2.6.33 and return and sort-like |
|
84
|
|
|
|
|
|
|
return code (1 => LHS bigger, 0 => equal, -1 => RHS bigger) |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
0.0 < 0.5 < 0.10 < 0.99 < 1 < 1.0~rc1 < 1.0 < 1.0+b1 < 1.0+nmu1 < 1.1 < 2.0 |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 cmp |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
See L<version_compare>. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Dominik Schulz, C<< <dominik.schulz at gauner.org> >> |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 BUGS |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-version-compare at rt.cpan.org>, or through |
|
99
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Version-Compare>. I will be notified, and then you'll |
|
100
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SUPPORT |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
perldoc Version::Compare |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
You can also look for information at: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Version-Compare> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Version-Compare> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Version-Compare> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * Search CPAN |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Version-Compare/> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Copyright 2012 Dominik Schulz |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
135
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
136
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
149
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |