16fb12b70Safresh1package version::regex; 26fb12b70Safresh1 36fb12b70Safresh1use strict; 46fb12b70Safresh1 5*3d61058aSafresh1our $VERSION = '0.9930'; 66fb12b70Safresh1 76fb12b70Safresh1#--------------------------------------------------------------------------# 86fb12b70Safresh1# Version regexp components 96fb12b70Safresh1#--------------------------------------------------------------------------# 106fb12b70Safresh1 116fb12b70Safresh1# Fraction part of a decimal version number. This is a common part of 126fb12b70Safresh1# both strict and lax decimal versions 136fb12b70Safresh1 146fb12b70Safresh1my $FRACTION_PART = qr/\.[0-9]+/; 156fb12b70Safresh1 166fb12b70Safresh1# First part of either decimal or dotted-decimal strict version number. 176fb12b70Safresh1# Unsigned integer with no leading zeroes (except for zero itself) to 186fb12b70Safresh1# avoid confusion with octal. 196fb12b70Safresh1 206fb12b70Safresh1my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/; 216fb12b70Safresh1 226fb12b70Safresh1# First part of either decimal or dotted-decimal lax version number. 236fb12b70Safresh1# Unsigned integer, but allowing leading zeros. Always interpreted 246fb12b70Safresh1# as decimal. However, some forms of the resulting syntax give odd 256fb12b70Safresh1# results if used as ordinary Perl expressions, due to how perl treats 266fb12b70Safresh1# octals. E.g. 276fb12b70Safresh1# version->new("010" ) == 10 286fb12b70Safresh1# version->new( 010 ) == 8 296fb12b70Safresh1# version->new( 010.2) == 82 # "8" . "2" 306fb12b70Safresh1 316fb12b70Safresh1my $LAX_INTEGER_PART = qr/[0-9]+/; 326fb12b70Safresh1 336fb12b70Safresh1# Second and subsequent part of a strict dotted-decimal version number. 346fb12b70Safresh1# Leading zeroes are permitted, and the number is always decimal. 356fb12b70Safresh1# Limited to three digits to avoid overflow when converting to decimal 366fb12b70Safresh1# form and also avoid problematic style with excessive leading zeroes. 376fb12b70Safresh1 386fb12b70Safresh1my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/; 396fb12b70Safresh1 406fb12b70Safresh1# Second and subsequent part of a lax dotted-decimal version number. 416fb12b70Safresh1# Leading zeroes are permitted, and the number is always decimal. No 426fb12b70Safresh1# limit on the numerical value or number of digits, so there is the 436fb12b70Safresh1# possibility of overflow when converting to decimal form. 446fb12b70Safresh1 456fb12b70Safresh1my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/; 466fb12b70Safresh1 476fb12b70Safresh1# Alpha suffix part of lax version number syntax. Acts like a 486fb12b70Safresh1# dotted-decimal part. 496fb12b70Safresh1 506fb12b70Safresh1my $LAX_ALPHA_PART = qr/_[0-9]+/; 516fb12b70Safresh1 526fb12b70Safresh1#--------------------------------------------------------------------------# 536fb12b70Safresh1# Strict version regexp definitions 546fb12b70Safresh1#--------------------------------------------------------------------------# 556fb12b70Safresh1 566fb12b70Safresh1# Strict decimal version number. 576fb12b70Safresh1 589f11ffb7Safresh1our $STRICT_DECIMAL_VERSION = 596fb12b70Safresh1 qr/ $STRICT_INTEGER_PART $FRACTION_PART? /x; 606fb12b70Safresh1 616fb12b70Safresh1# Strict dotted-decimal version number. Must have both leading "v" and 626fb12b70Safresh1# at least three parts, to avoid confusion with decimal syntax. 636fb12b70Safresh1 649f11ffb7Safresh1our $STRICT_DOTTED_DECIMAL_VERSION = 656fb12b70Safresh1 qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} /x; 666fb12b70Safresh1 676fb12b70Safresh1# Complete strict version number syntax -- should generally be used 686fb12b70Safresh1# anchored: qr/ \A $STRICT \z /x 696fb12b70Safresh1 709f11ffb7Safresh1our $STRICT = 716fb12b70Safresh1 qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x; 726fb12b70Safresh1 736fb12b70Safresh1#--------------------------------------------------------------------------# 746fb12b70Safresh1# Lax version regexp definitions 756fb12b70Safresh1#--------------------------------------------------------------------------# 766fb12b70Safresh1 776fb12b70Safresh1# Lax decimal version number. Just like the strict one except for 786fb12b70Safresh1# allowing an alpha suffix or allowing a leading or trailing 796fb12b70Safresh1# decimal-point 806fb12b70Safresh1 819f11ffb7Safresh1our $LAX_DECIMAL_VERSION = 829f11ffb7Safresh1 qr/ $LAX_INTEGER_PART (?: $FRACTION_PART | \. )? $LAX_ALPHA_PART? 836fb12b70Safresh1 | 846fb12b70Safresh1 $FRACTION_PART $LAX_ALPHA_PART? 856fb12b70Safresh1 /x; 866fb12b70Safresh1 876fb12b70Safresh1# Lax dotted-decimal version number. Distinguished by having either 886fb12b70Safresh1# leading "v" or at least three non-alpha parts. Alpha part is only 896fb12b70Safresh1# permitted if there are at least two non-alpha parts. Strangely 906fb12b70Safresh1# enough, without the leading "v", Perl takes .1.2 to mean v0.1.2, 916fb12b70Safresh1# so when there is no "v", the leading part is optional 926fb12b70Safresh1 939f11ffb7Safresh1our $LAX_DOTTED_DECIMAL_VERSION = 946fb12b70Safresh1 qr/ 956fb12b70Safresh1 v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )? 966fb12b70Safresh1 | 976fb12b70Safresh1 $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART? 986fb12b70Safresh1 /x; 996fb12b70Safresh1 1006fb12b70Safresh1# Complete lax version number syntax -- should generally be used 1016fb12b70Safresh1# anchored: qr/ \A $LAX \z /x 1026fb12b70Safresh1# 1036fb12b70Safresh1# The string 'undef' is a special case to make for easier handling 1046fb12b70Safresh1# of return values from ExtUtils::MM->parse_version 1056fb12b70Safresh1 1069f11ffb7Safresh1our $LAX = 1079f11ffb7Safresh1 qr/ undef | $LAX_DOTTED_DECIMAL_VERSION | $LAX_DECIMAL_VERSION /x; 1086fb12b70Safresh1 1096fb12b70Safresh1#--------------------------------------------------------------------------# 1106fb12b70Safresh1 1116fb12b70Safresh1# Preloaded methods go here. 1126fb12b70Safresh1sub is_strict { defined $_[0] && $_[0] =~ qr/ \A $STRICT \z /x } 1136fb12b70Safresh1sub is_lax { defined $_[0] && $_[0] =~ qr/ \A $LAX \z /x } 1146fb12b70Safresh1 1156fb12b70Safresh11; 116