line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
1181
|
use 5.008; # utf8 |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
16
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
1059
|
use utf8; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Dist::Zilla::Role::Version::Sanitize; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002001'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Sanitize a version from a plugin |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
627
|
use Moose::Role qw(has around); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints qw(enum); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _normalize_normal { |
29
|
|
|
|
|
|
|
my ( undef, $orig ) = @_; |
30
|
|
|
|
|
|
|
require version; |
31
|
|
|
|
|
|
|
return version->parse($orig)->normal; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _normalize_normal_3 { |
35
|
|
|
|
|
|
|
my ( undef, $orig ) = @_; |
36
|
|
|
|
|
|
|
require version; |
37
|
|
|
|
|
|
|
my $v = version->parse($orig)->normal; |
38
|
|
|
|
|
|
|
$v =~ s/\Av//msx; |
39
|
|
|
|
|
|
|
if ( $v !~ /\A\d+[.]\d+[.]\d+/msx ) { |
40
|
|
|
|
|
|
|
require Carp; |
41
|
|
|
|
|
|
|
return Carp::croak("Normalised string $v does not have a minimum of 3 parts"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
return $v; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _normalize_numify { |
47
|
|
|
|
|
|
|
my ( $self, $orig ) = @_; |
48
|
|
|
|
|
|
|
require version; |
49
|
|
|
|
|
|
|
my $version = version->parse($orig)->numify; |
50
|
|
|
|
|
|
|
if ( $version =~ /(\A\d+)[.](.*$)/msx ) { |
51
|
|
|
|
|
|
|
my ( $sig, $mantissa ) = ( $1, $2 ); |
52
|
|
|
|
|
|
|
my $got = length $mantissa; |
53
|
|
|
|
|
|
|
my $want = $self->mantissa; |
54
|
|
|
|
|
|
|
if ( $got == $want ) { |
55
|
|
|
|
|
|
|
return $version; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
$self->log( [ 'MANTISSA LENGTH != EXPECTED: WANTED %s, GOT %s, CORRECTING', $want, $got ] ); |
58
|
|
|
|
|
|
|
if ( $want < $got ) { |
59
|
|
|
|
|
|
|
my $newman = substr $mantissa, 0, $want; |
60
|
|
|
|
|
|
|
return $sig . q[.] . $newman; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
my $need = $want - $got; |
63
|
|
|
|
|
|
|
return $sig . q[.] . $mantissa . ( q[0] x $need ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
require Carp; |
66
|
|
|
|
|
|
|
return Carp::croak(qq[Could not parse mantissa from numified version $version]); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my %normal_forms = ( |
109
|
|
|
|
|
|
|
normal => '_normalize_normal', |
110
|
|
|
|
|
|
|
normal_3 => '_normalize_normal_3', |
111
|
|
|
|
|
|
|
numify => '_normalize_numify', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
has normal_form => ( |
123
|
|
|
|
|
|
|
is => ro =>, |
124
|
|
|
|
|
|
|
isa => enum( [ keys %normal_forms ] ), |
125
|
|
|
|
|
|
|
is => 'ro', |
126
|
|
|
|
|
|
|
lazy => 1, |
127
|
|
|
|
|
|
|
default => sub { return 'numify' }, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
has mantissa => ( |
148
|
|
|
|
|
|
|
is => ro =>, |
149
|
|
|
|
|
|
|
isa => 'Int', |
150
|
|
|
|
|
|
|
is => 'ro', |
151
|
|
|
|
|
|
|
lazy => 1, |
152
|
|
|
|
|
|
|
default => sub { |
153
|
|
|
|
|
|
|
## no critic (ProhibitMagicNumbers |
154
|
|
|
|
|
|
|
return 6; |
155
|
|
|
|
|
|
|
}, |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
around provide_version => sub { |
159
|
|
|
|
|
|
|
my ( $orig, $self, @args ) = @_; |
160
|
|
|
|
|
|
|
my $v = $orig->( $self, @args ); |
161
|
|
|
|
|
|
|
my $method = $normal_forms{ $self->normal_form }; |
162
|
|
|
|
|
|
|
my $fixed = $self->$method($v); |
163
|
|
|
|
|
|
|
if ( "$fixed" ne "$v" ) { |
164
|
|
|
|
|
|
|
$self->log("Version normalised from $v to $fixed"); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
return $fixed; |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
around dump_config => sub { |
170
|
|
|
|
|
|
|
my ( $orig, $self, @args ) = @_; |
171
|
|
|
|
|
|
|
my $config = $orig->( $self, @args ); |
172
|
|
|
|
|
|
|
my $own_config = { |
173
|
|
|
|
|
|
|
normal_form => $self->normal_form, |
174
|
|
|
|
|
|
|
mantissa => $self->mantissa, |
175
|
|
|
|
|
|
|
}; |
176
|
|
|
|
|
|
|
$config->{ q[] . __PACKAGE__ } = $own_config; |
177
|
|
|
|
|
|
|
return $config; |
178
|
|
|
|
|
|
|
}; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
no Moose::Role; |
181
|
|
|
|
|
|
|
no Moose::Util::TypeConstraints; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
__END__ |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=pod |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=encoding UTF-8 |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 NAME |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Dist::Zilla::Role::Version::Sanitize - Sanitize a version from a plugin |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 VERSION |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
version 0.002001 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 C<normal_form> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Determines which L<< I<normal form>|/NORMAL FORMS >> is used. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Default is : B<< C<numify> >> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 C<mantissa> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Determines the mandatory length of the C<mantissa> for the L<< C<numify>|/numify >> normal form. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Default is : B<< C<6> >> |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Which yields: |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
1.001001 |
216
|
|
|
|
|
|
|
10.001001 |
217
|
|
|
|
|
|
|
100.001001 |
218
|
|
|
|
|
|
|
1000.001001 |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Etc. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=begin MetaPOD::JSON v1.1.0 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
"namespace":"Dist::Zilla::Role::Version::Sanitize", |
226
|
|
|
|
|
|
|
"interface":"role" |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=end MetaPOD::JSON |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 NORMAL FORMS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 C<normal> |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Normalizes to the notation: |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
v1 |
239
|
|
|
|
|
|
|
v1.2 |
240
|
|
|
|
|
|
|
v1.2.3 |
241
|
|
|
|
|
|
|
v1.2.3.4 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 C<normal_3> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Normalizes to the notation |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1.2.3 |
248
|
|
|
|
|
|
|
1.2.3.4 |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Note: Due to the absence of the leading C<v>, 3, is the minimum number of places that can be represented in this notation. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Accidentally normalizing to |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1.2 |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
In this form should raise a fatal exception. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 C<numify> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Normalizes to the notation |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
1.23456789 |
263
|
|
|
|
|
|
|
| ^------^--- The Mantissa |
264
|
|
|
|
|
|
|
| |
265
|
|
|
|
|
|
|
^------------ Integer part. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
And the length for mantissa is forced by C<mantissa>, either I<truncating> to C<mantissa> length, or C<paddding> to C<mantissa> length with C<0>'s |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 AUTHOR |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Kent Fredric <kentfredric@gmail.com> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
278
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=cut |