This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-MakeMaker to CPAN version 7.38
[perl5.git] / cpan / ExtUtils-MakeMaker / lib / ExtUtils / MakeMaker / version / regex.pm
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 use strict;
10
11 use vars qw($VERSION $CLASS $STRICT $LAX);
12
13 $VERSION = '7.38';
14 $VERSION =~ tr/_//d;
15
16 #--------------------------------------------------------------------------#
17 # Version regexp components
18 #--------------------------------------------------------------------------#
19
20 # Fraction part of a decimal version number.  This is a common part of
21 # both strict and lax decimal versions
22
23 my $FRACTION_PART = qr/\.[0-9]+/;
24
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.
28
29 my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/;
30
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
35 # octals.  E.g.
36 #   version->new("010" ) == 10
37 #   version->new( 010  ) == 8
38 #   version->new( 010.2) == 82  # "8" . "2"
39
40 my $LAX_INTEGER_PART = qr/[0-9]+/;
41
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.
46
47 my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/;
48
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.
53
54 my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/;
55
56 # Alpha suffix part of lax version number syntax.  Acts like a
57 # dotted-decimal part.
58
59 my $LAX_ALPHA_PART = qr/_[0-9]+/;
60
61 #--------------------------------------------------------------------------#
62 # Strict version regexp definitions
63 #--------------------------------------------------------------------------#
64
65 # Strict decimal version number.
66
67 my $STRICT_DECIMAL_VERSION =
68     qr/ $STRICT_INTEGER_PART $FRACTION_PART? /x;
69
70 # Strict dotted-decimal version number.  Must have both leading "v" and
71 # at least three parts, to avoid confusion with decimal syntax.
72
73 my $STRICT_DOTTED_DECIMAL_VERSION =
74     qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} /x;
75
76 # Complete strict version number syntax -- should generally be used
77 # anchored: qr/ \A $STRICT \z /x
78
79 $STRICT =
80     qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x;
81
82 #--------------------------------------------------------------------------#
83 # Lax version regexp definitions
84 #--------------------------------------------------------------------------#
85
86 # Lax decimal version number.  Just like the strict one except for
87 # allowing an alpha suffix or allowing a leading or trailing
88 # decimal-point
89
90 my $LAX_DECIMAL_VERSION =
91     qr/ $LAX_INTEGER_PART (?: \. | $FRACTION_PART $LAX_ALPHA_PART? )?
92         |
93         $FRACTION_PART $LAX_ALPHA_PART?
94     /x;
95
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
101
102 my $LAX_DOTTED_DECIMAL_VERSION =
103     qr/
104         v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )?
105         |
106         $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART?
107     /x;
108
109 # Complete lax version number syntax -- should generally be used
110 # anchored: qr/ \A $LAX \z /x
111 #
112 # The string 'undef' is a special case to make for easier handling
113 # of return values from ExtUtils::MM->parse_version
114
115 $LAX =
116     qr/ undef | $LAX_DECIMAL_VERSION | $LAX_DOTTED_DECIMAL_VERSION /x;
117
118 #--------------------------------------------------------------------------#
119
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 }
123
124 1;