line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
6
|
|
|
6
|
|
17543
|
use 5.006; # our |
|
6
|
|
|
|
|
14
|
|
2
|
6
|
|
|
6
|
|
25
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
186
|
|
3
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
392
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dist::Zilla::Role::Version::Sanitize; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.002003'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Sanitize a version from a plugin |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
873
|
use Moose::Role qw(has around); |
|
6
|
|
|
|
|
609873
|
|
|
6
|
|
|
|
|
37
|
|
14
|
6
|
|
|
6
|
|
18068
|
use Moose::Util::TypeConstraints qw(enum); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
42
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _normalize_normal { |
28
|
1
|
|
|
1
|
|
2
|
my ( undef, $orig ) = @_; |
29
|
1
|
|
|
|
|
6
|
require version; |
30
|
1
|
|
|
|
|
14
|
return version->parse($orig)->normal; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _normalize_normal_3 { |
34
|
1
|
|
|
1
|
|
2
|
my ( undef, $orig ) = @_; |
35
|
1
|
|
|
|
|
66
|
require version; |
36
|
1
|
|
|
|
|
25
|
my $v = version->parse($orig)->normal; |
37
|
1
|
|
|
|
|
7
|
$v =~ s/\Av//msx; |
38
|
1
|
50
|
|
|
|
7
|
if ( $v !~ /\A\d+[.]\d+[.]\d+/msx ) { |
39
|
0
|
|
|
|
|
0
|
require Carp; |
40
|
0
|
|
|
|
|
0
|
return Carp::croak("Normalised string $v does not have a minimum of 3 parts"); |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
3
|
return $v; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _normalize_numify { |
46
|
3
|
|
|
3
|
|
9
|
my ( $self, $orig ) = @_; |
47
|
3
|
|
|
|
|
23
|
require version; |
48
|
3
|
|
|
|
|
45
|
my $version = version->parse($orig)->numify; |
49
|
3
|
50
|
|
|
|
23
|
if ( $version =~ /(\A\d+)[.](.*$)/msx ) { |
50
|
3
|
|
|
|
|
10
|
my ( $sig, $mantissa ) = ( $1, $2 ); |
51
|
3
|
|
|
|
|
5
|
my $got = length $mantissa; |
52
|
3
|
|
|
|
|
93
|
my $want = $self->mantissa; |
53
|
3
|
100
|
|
|
|
12
|
if ( $got == $want ) { |
54
|
1
|
|
|
|
|
3
|
return $version; |
55
|
|
|
|
|
|
|
} |
56
|
2
|
|
|
|
|
13
|
$self->log( [ 'MANTISSA LENGTH != EXPECTED: WANTED %s, GOT %s, CORRECTING', $want, $got ] ); |
57
|
2
|
100
|
|
|
|
740
|
if ( $want < $got ) { |
58
|
1
|
|
|
|
|
3
|
my $newman = substr $mantissa, 0, $want; |
59
|
1
|
|
|
|
|
3
|
return $sig . q[.] . $newman; |
60
|
|
|
|
|
|
|
} |
61
|
1
|
|
|
|
|
3
|
my $need = $want - $got; |
62
|
1
|
|
|
|
|
4
|
return $sig . q[.] . $mantissa . ( q[0] x $need ); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
require Carp; |
65
|
0
|
|
|
|
|
|
return Carp::croak(qq[Could not parse mantissa from numified version $version]); |
66
|
|
|
|
|
|
|
} |
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
|
|
|
|
|
|
|
my %normal_forms = ( |
108
|
|
|
|
|
|
|
normal => '_normalize_normal', |
109
|
|
|
|
|
|
|
normal_3 => '_normalize_normal_3', |
110
|
|
|
|
|
|
|
numify => '_normalize_numify', |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
has normal_form => ( |
122
|
|
|
|
|
|
|
is => ro =>, |
123
|
|
|
|
|
|
|
isa => enum( [ keys %normal_forms ] ), |
124
|
|
|
|
|
|
|
is => 'ro', |
125
|
|
|
|
|
|
|
lazy => 1, |
126
|
|
|
|
|
|
|
default => sub { return 'numify' }, |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
has mantissa => ( |
147
|
|
|
|
|
|
|
is => ro =>, |
148
|
|
|
|
|
|
|
isa => 'Int', |
149
|
|
|
|
|
|
|
is => 'ro', |
150
|
|
|
|
|
|
|
lazy => 1, |
151
|
|
|
|
|
|
|
default => sub { |
152
|
|
|
|
|
|
|
## no critic (ProhibitMagicNumbers |
153
|
|
|
|
|
|
|
return 6; |
154
|
|
|
|
|
|
|
}, |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
around provide_version => sub { |
158
|
|
|
|
|
|
|
my ( $orig, $self, @args ) = @_; |
159
|
|
|
|
|
|
|
my $v = $orig->( $self, @args ); |
160
|
|
|
|
|
|
|
my $method = $normal_forms{ $self->normal_form }; |
161
|
|
|
|
|
|
|
my $fixed = $self->$method($v); |
162
|
|
|
|
|
|
|
if ( "$fixed" ne "$v" ) { |
163
|
|
|
|
|
|
|
$self->log("Version normalised from $v to $fixed"); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
return $fixed; |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
around dump_config => sub { |
169
|
|
|
|
|
|
|
my ( $orig, $self, @args ) = @_; |
170
|
|
|
|
|
|
|
my $config = $orig->( $self, @args ); |
171
|
|
|
|
|
|
|
my $localconf = $config->{ +__PACKAGE__ } = {}; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$localconf->{normal_form} = $self->normal_form; |
174
|
|
|
|
|
|
|
$localconf->{mantissa} = $self->mantissa; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION; |
177
|
|
|
|
|
|
|
return $config; |
178
|
|
|
|
|
|
|
}; |
179
|
|
|
|
|
|
|
|
180
|
6
|
|
|
6
|
|
5177
|
no Moose::Role; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
29
|
|
181
|
6
|
|
|
6
|
|
624
|
no Moose::Util::TypeConstraints; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
27
|
|
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.002003 |
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 <kentnl@cpan.org> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
This software is copyright (c) 2017 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 |