line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package version::Normal; |
3
|
|
|
|
|
|
|
$version::Normal::VERSION = '0.1.1'; |
4
|
|
|
|
|
|
|
# ABSTRACT: More normal forms for version objects |
5
|
2
|
|
|
2
|
|
51619
|
use 5.012; |
|
2
|
|
|
|
|
11
|
|
6
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
44
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
696
|
use version 0.77 (); |
|
2
|
|
|
|
|
2908
|
|
|
2
|
|
|
|
|
434
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub version::normal2 { |
11
|
11
|
|
|
11
|
0
|
13142
|
&_check_version; |
12
|
|
|
|
|
|
|
|
13
|
11
|
|
|
|
|
17
|
my @v = @{ $_[0]{version} }; |
|
11
|
|
|
|
|
33
|
|
14
|
11
|
|
100
|
|
|
46
|
pop @v while @v > 2 && !$v[-1]; # drop trailing 0's |
15
|
|
|
|
|
|
|
|
16
|
11
|
|
|
|
|
20
|
push @v, 0 while @v < 2; # at least 2 parts |
17
|
|
|
|
|
|
|
|
18
|
11
|
|
|
|
|
68
|
return sprintf 'v%vd', pack 'U*', @v; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub version::normal3 { |
22
|
11
|
|
|
11
|
0
|
36
|
&_check_version; |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
20
|
my @v = @{ $_[0]{version} }; |
|
11
|
|
|
|
|
16
|
|
25
|
11
|
|
66
|
|
|
30
|
pop @v while @v > 3 && !$v[-1]; # drop trailing 0's |
26
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
23
|
push @v, 0 while @v < 3; # at least 3 parts |
28
|
|
|
|
|
|
|
|
29
|
11
|
|
|
|
|
39
|
return sprintf '%vd', pack 'U*', @v; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _check_version { |
33
|
|
|
|
|
|
|
ref( $_[0] ) |
34
|
22
|
|
|
|
|
103
|
&& eval { exists $_[0]{version} } |
35
|
22
|
50
|
33
|
22
|
|
53
|
&& ref( $_[0]{version} ) eq 'ARRAY' |
|
|
|
33
|
|
|
|
|
36
|
|
|
|
|
|
|
and return; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
require Carp; |
39
|
0
|
|
|
|
|
|
Carp::croak("Invalid version object"); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#pod =encoding utf8 |
45
|
|
|
|
|
|
|
#pod |
46
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
47
|
|
|
|
|
|
|
#pod |
48
|
|
|
|
|
|
|
#pod use version::Normal; |
49
|
|
|
|
|
|
|
#pod |
50
|
|
|
|
|
|
|
#pod # 'v0.400' |
51
|
|
|
|
|
|
|
#pod version->parse('0.4')->normal2; |
52
|
|
|
|
|
|
|
#pod |
53
|
|
|
|
|
|
|
#pod # '0.400.0' |
54
|
|
|
|
|
|
|
#pod version->parse('0.4')->normal3; |
55
|
|
|
|
|
|
|
#pod |
56
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
57
|
|
|
|
|
|
|
#pod |
58
|
|
|
|
|
|
|
#pod B |
59
|
|
|
|
|
|
|
#pod |
60
|
|
|
|
|
|
|
#pod This module loads the L module and adds two methods to its objects. |
61
|
|
|
|
|
|
|
#pod Those methods implement normal forms akin to the standard C method. |
62
|
|
|
|
|
|
|
#pod |
63
|
|
|
|
|
|
|
#pod Furthermore, these normal forms have the following property: |
64
|
|
|
|
|
|
|
#pod |
65
|
|
|
|
|
|
|
#pod NORMAL(v1) = NORMAL(v2) if v1 == v2 |
66
|
|
|
|
|
|
|
#pod |
67
|
|
|
|
|
|
|
#pod Notice that this property does not hold for C. |
68
|
|
|
|
|
|
|
#pod For example, for two version numbers like C<'v1.0.0'> |
69
|
|
|
|
|
|
|
#pod and C<'v1.0.0.0'> which satisfy |
70
|
|
|
|
|
|
|
#pod |
71
|
|
|
|
|
|
|
#pod version->parse('v1.0.0') == version->parse('v1.0.0.0') |
72
|
|
|
|
|
|
|
#pod |
73
|
|
|
|
|
|
|
#pod the following table of results can be computed |
74
|
|
|
|
|
|
|
#pod |
75
|
|
|
|
|
|
|
#pod V 'v1.0.0' 'v1.0.0.0' |
76
|
|
|
|
|
|
|
#pod |
77
|
|
|
|
|
|
|
#pod version->parse(V)->normal() 'v1.0.0' ≠ 'v1.0.0.0' |
78
|
|
|
|
|
|
|
#pod version->parse(V)->normal2() 'v1.0' = 'v1.0' |
79
|
|
|
|
|
|
|
#pod version->parse(V)->normal3() '1.0.0' = '1.0.0' |
80
|
|
|
|
|
|
|
#pod |
81
|
|
|
|
|
|
|
#pod =head1 METHODS |
82
|
|
|
|
|
|
|
#pod |
83
|
|
|
|
|
|
|
#pod L implements the following methods |
84
|
|
|
|
|
|
|
#pod and installs them into L namespace. |
85
|
|
|
|
|
|
|
#pod |
86
|
|
|
|
|
|
|
#pod =head2 normal2 |
87
|
|
|
|
|
|
|
#pod |
88
|
|
|
|
|
|
|
#pod $string = $version->normal2(); |
89
|
|
|
|
|
|
|
#pod |
90
|
|
|
|
|
|
|
#pod Returns a string with a normalized dotted-decimal form with a leading-v, |
91
|
|
|
|
|
|
|
#pod at least 2 components, and no superfluous trailing 0. |
92
|
|
|
|
|
|
|
#pod |
93
|
|
|
|
|
|
|
#pod Some examples are: |
94
|
|
|
|
|
|
|
#pod |
95
|
|
|
|
|
|
|
#pod V version->parse(V)->normal2() |
96
|
|
|
|
|
|
|
#pod |
97
|
|
|
|
|
|
|
#pod 0.1 v0.100 |
98
|
|
|
|
|
|
|
#pod v0.1 v0.1 |
99
|
|
|
|
|
|
|
#pod v1 v1.0 |
100
|
|
|
|
|
|
|
#pod 0.010 v0.10 |
101
|
|
|
|
|
|
|
#pod 1.010 v1.10 |
102
|
|
|
|
|
|
|
#pod 0.3.10 v0.3.10 |
103
|
|
|
|
|
|
|
#pod v0.0.0.0 v0.0 |
104
|
|
|
|
|
|
|
#pod v0.1.0.0 v0.1 |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod This form looks good when describing the version of a software |
107
|
|
|
|
|
|
|
#pod component for humans to read |
108
|
|
|
|
|
|
|
#pod (eg. at C file, C<--version> output, etc.) |
109
|
|
|
|
|
|
|
#pod |
110
|
|
|
|
|
|
|
#pod =head2 normal3 |
111
|
|
|
|
|
|
|
#pod |
112
|
|
|
|
|
|
|
#pod $string = $version->normal3(); |
113
|
|
|
|
|
|
|
#pod |
114
|
|
|
|
|
|
|
#pod Returns a string with a normalized dotted-decimal form with no leading-v, |
115
|
|
|
|
|
|
|
#pod at least 3 components, and no superfluous trailing 0. |
116
|
|
|
|
|
|
|
#pod |
117
|
|
|
|
|
|
|
#pod Some examples are: |
118
|
|
|
|
|
|
|
#pod |
119
|
|
|
|
|
|
|
#pod V version->parse(V)->normal3() |
120
|
|
|
|
|
|
|
#pod |
121
|
|
|
|
|
|
|
#pod 0.1 0.100.0 |
122
|
|
|
|
|
|
|
#pod v0.1 0.1.0 |
123
|
|
|
|
|
|
|
#pod v1 1.0.0 |
124
|
|
|
|
|
|
|
#pod 0.010 0.10.0 |
125
|
|
|
|
|
|
|
#pod 1.010 1.10.0 |
126
|
|
|
|
|
|
|
#pod 0.3.10 0.3.10 |
127
|
|
|
|
|
|
|
#pod v0.0.0.0 0.0.0 |
128
|
|
|
|
|
|
|
#pod v0.1.0.0 0.1.0 |
129
|
|
|
|
|
|
|
#pod |
130
|
|
|
|
|
|
|
#pod This form is appropriate for distribution tarball names |
131
|
|
|
|
|
|
|
#pod (like C<"version-Normal-0.1.0.tar.gz">) – only digits and dots |
132
|
|
|
|
|
|
|
#pod and no need for special interpretation of a leading-v. |
133
|
|
|
|
|
|
|
#pod |
134
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
135
|
|
|
|
|
|
|
#pod |
136
|
|
|
|
|
|
|
#pod L |
137
|
|
|
|
|
|
|
#pod |
138
|
|
|
|
|
|
|
#pod =head1 ACKNOWLEDGEMENTS |
139
|
|
|
|
|
|
|
#pod |
140
|
|
|
|
|
|
|
#pod The development of this library has been partially sponsored |
141
|
|
|
|
|
|
|
#pod by Connectivity, Inc. |
142
|
|
|
|
|
|
|
#pod |
143
|
|
|
|
|
|
|
#pod =cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |