File Coverage

lib/ExtUtils/MakeMaker/version/regex.pm
Criterion Covered Total %
statement 9 11 81.8
branch 0 4 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 22 54.5


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