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 #--------------------------------------------------------------------------#
7 package ExtUtils::MakeMaker::version::regex;
11 use vars qw($VERSION $CLASS $STRICT $LAX);
16 #--------------------------------------------------------------------------#
17 # Version regexp components
18 #--------------------------------------------------------------------------#
20 # Fraction part of a decimal version number. This is a common part of
21 # both strict and lax decimal versions
23 my $FRACTION_PART = qr/\.[0-9]+/;
25 # First part of either decimal or dotted-decimal strict version number.
26 # Unsigned integer with no leading zeroes (except for zero itself) to
27 # avoid confusion with octal.
29 my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/;
31 # First part of either decimal or dotted-decimal lax version number.
32 # Unsigned integer, but allowing leading zeros. Always interpreted
33 # as decimal. However, some forms of the resulting syntax give odd
34 # results if used as ordinary Perl expressions, due to how perl treats
36 # version->new("010" ) == 10
37 # version->new( 010 ) == 8
38 # version->new( 010.2) == 82 # "8" . "2"
40 my $LAX_INTEGER_PART = qr/[0-9]+/;
42 # Second and subsequent part of a strict dotted-decimal version number.
43 # Leading zeroes are permitted, and the number is always decimal.
44 # Limited to three digits to avoid overflow when converting to decimal
45 # form and also avoid problematic style with excessive leading zeroes.
47 my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/;
49 # Second and subsequent part of a lax dotted-decimal version number.
50 # Leading zeroes are permitted, and the number is always decimal. No
51 # limit on the numerical value or number of digits, so there is the
52 # possibility of overflow when converting to decimal form.
54 my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/;
56 # Alpha suffix part of lax version number syntax. Acts like a
57 # dotted-decimal part.
59 my $LAX_ALPHA_PART = qr/_[0-9]+/;
61 #--------------------------------------------------------------------------#
62 # Strict version regexp definitions
63 #--------------------------------------------------------------------------#
65 # Strict decimal version number.
67 my $STRICT_DECIMAL_VERSION =
68 qr/ $STRICT_INTEGER_PART $FRACTION_PART? /x;
70 # Strict dotted-decimal version number. Must have both leading "v" and
71 # at least three parts, to avoid confusion with decimal syntax.
73 my $STRICT_DOTTED_DECIMAL_VERSION =
74 qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} /x;
76 # Complete strict version number syntax -- should generally be used
77 # anchored: qr/ \A $STRICT \z /x
80 qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x;
82 #--------------------------------------------------------------------------#
83 # Lax version regexp definitions
84 #--------------------------------------------------------------------------#
86 # Lax decimal version number. Just like the strict one except for
87 # allowing an alpha suffix or allowing a leading or trailing
90 my $LAX_DECIMAL_VERSION =
91 qr/ $LAX_INTEGER_PART (?: \. | $FRACTION_PART $LAX_ALPHA_PART? )?
93 $FRACTION_PART $LAX_ALPHA_PART?
96 # Lax dotted-decimal version number. Distinguished by having either
97 # leading "v" or at least three non-alpha parts. Alpha part is only
98 # permitted if there are at least two non-alpha parts. Strangely
99 # enough, without the leading "v", Perl takes .1.2 to mean v0.1.2,
100 # so when there is no "v", the leading part is optional
102 my $LAX_DOTTED_DECIMAL_VERSION =
104 v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )?
106 $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART?
109 # Complete lax version number syntax -- should generally be used
110 # anchored: qr/ \A $LAX \z /x
112 # The string 'undef' is a special case to make for easier handling
113 # of return values from ExtUtils::MM->parse_version
116 qr/ undef | $LAX_DECIMAL_VERSION | $LAX_DOTTED_DECIMAL_VERSION /x;
118 #--------------------------------------------------------------------------#
120 # Preloaded methods go here.
121 sub is_strict { defined $_[0] && $_[0] =~ qr/ \A $STRICT \z /x }
122 sub is_lax { defined $_[0] && $_[0] =~ qr/ \A $LAX \z /x }