version/regex.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 29 CC 1 SCAR 6.9
CC
1
Cov
0%
is_strict
2.0
is_lax
2.0
BEGIN
2.0
CRAP 2.0
1 package version::regex;
2  
3 use strict;
4  
5 our $VERSION = '0.9924_02';
6  
7 #--------------------------------------------------------------------------#
8 # Version regexp components
9 #--------------------------------------------------------------------------#
10  
11 # Fraction part of a decimal version number. This is a common part of
12 # both strict and lax decimal versions
13  
14 my $FRACTION_PART = qr/\.[0-9]+/;
15  
16 # First part of either decimal or dotted-decimal strict version number.
17 # Unsigned integer with no leading zeroes (except for zero itself) to
18 # avoid confusion with octal.
19  
20 my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/;
21  
22 # First part of either decimal or dotted-decimal lax version number.
23 # Unsigned integer, but allowing leading zeros. Always interpreted
24 # as decimal. However, some forms of the resulting syntax give odd
25 # results if used as ordinary Perl expressions, due to how perl treats
26 # octals. E.g.
27 # version->new("010" ) == 10
28 # version->new( 010 ) == 8
29 # version->new( 010.2) == 82 # "8" . "2"
30  
31 my $LAX_INTEGER_PART = qr/[0-9]+/;
32  
33 # Second and subsequent part of a strict dotted-decimal version number.
34 # Leading zeroes are permitted, and the number is always decimal.
35 # Limited to three digits to avoid overflow when converting to decimal
36 # form and also avoid problematic style with excessive leading zeroes.
37  
38 my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/;
39  
40 # Second and subsequent part of a lax dotted-decimal version number.
41 # Leading zeroes are permitted, and the number is always decimal. No
42 # limit on the numerical value or number of digits, so there is the
43 # possibility of overflow when converting to decimal form.
44  
45 my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/;
46  
47 # Alpha suffix part of lax version number syntax. Acts like a
48 # dotted-decimal part.
49  
50 #my $LAX_ALPHA_PART = qr/_[0-9]+/;
51 my $LAX_ALPHA_PART = qr/(?:_[0-9]+c?|c?)/;
52  
53 #--------------------------------------------------------------------------#
54 # Strict version regexp definitions
55 #--------------------------------------------------------------------------#
56  
57 # Strict decimal version number.
58  
59 our $STRICT_DECIMAL_VERSION =
60 qr/ $STRICT_INTEGER_PART $FRACTION_PART? c? /x;
61  
62 # Strict dotted-decimal version number. Must have both leading "v" and
63 # at least three parts, to avoid confusion with decimal syntax.
64  
65 our $STRICT_DOTTED_DECIMAL_VERSION =
66 qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} c? /x;
67  
68 # Complete strict version number syntax -- should generally be used
69 # anchored: qr/ \A $STRICT \z /x
70  
71 our $STRICT =
72 qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x;
73  
74 #--------------------------------------------------------------------------#
75 # Lax version regexp definitions
76 #--------------------------------------------------------------------------#
77  
78 # Lax decimal version number. Just like the strict one except for
79 # allowing an alpha suffix or allowing a leading or trailing
80 # decimal-point
81  
82 our $LAX_DECIMAL_VERSION =
83 qr/ $LAX_INTEGER_PART (?: $FRACTION_PART | \. )? $LAX_ALPHA_PART?
84 |
85 $FRACTION_PART $LAX_ALPHA_PART?
86 /x;
87  
88 # Lax dotted-decimal version number. Distinguished by having either
89 # leading "v" or at least three non-alpha parts. Alpha part is only
90 # permitted if there are at least two non-alpha parts. Strangely
91 # enough, without the leading "v", Perl takes .1.2 to mean v0.1.2,
92 # so when there is no "v", the leading part is optional
93  
94 our $LAX_DOTTED_DECIMAL_VERSION =
95 qr/
96 v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )?
97 |
98 $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART?
99 /x;
100  
101 # Complete lax version number syntax -- should generally be used
102 # anchored: qr/ \A $LAX \z /x
103 #
104 # The string 'undef' is a special case to make for easier handling
105 # of return values from ExtUtils::MM->parse_version
106  
107 our $LAX =
108 qr/ undef | $LAX_DOTTED_DECIMAL_VERSION | $LAX_DECIMAL_VERSION /x;
109  
110 #--------------------------------------------------------------------------#
111  
112 # Preloaded methods go here.
113 sub is_strict { defined $_[0] && $_[0] =~ qr/ \A $STRICT \z /x }
114 sub is_lax { defined $_[0] && $_[0] =~ qr/ \A $LAX \z /x }
115  
116 1;