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