This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlbug: Ask confirmation if would overwrite existing file
[perl5.git] / cpan / version / lib / version.pm
CommitLineData
c8d69e4a 1#!perl -w
a7ad731c
HS
2package version;
3
05402f6b 4use 5.006002;
a7ad731c 5use strict;
14f3031b
JP
6use warnings::register;
7if ($] >= 5.015) {
8 warnings::register_categories(qw/version/);
9}
a7ad731c 10
effa684c 11use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
a7ad731c 12
d3a5b29c 13$VERSION = 0.9921;
a7ad731c
HS
14$CLASS = 'version';
15
16885730 16# avoid using Exporter
0a24517e 17require version::regex;
16885730
JP
18*version::is_lax = \&version::regex::is_lax;
19*version::is_strict = \&version::regex::is_strict;
db9cb848 20*LAX = \$version::regex::LAX;
dddb2275
JP
21*LAX_DECIMAL_VERSION = \$version::regex::LAX_DECIMAL_VERSION;
22*LAX_DOTTED_DECIMAL_VERSION = \$version::regex::LAX_DOTTED_DECIMAL_VERSION;
db9cb848 23*STRICT = \$version::regex::STRICT;
dddb2275
JP
24*STRICT_DECIMAL_VERSION = \$version::regex::STRICT_DECIMAL_VERSION;
25*STRICT_DOTTED_DECIMAL_VERSION = \$version::regex::STRICT_DOTTED_DECIMAL_VERSION;
91152fc1 26
c8a14fb6 27sub import {
c8a14fb6 28 no strict 'refs';
f941e658
JP
29 my ($class) = shift;
30
31 # Set up any derived class
4141ef59 32 unless ($class eq $CLASS) {
f941e658 33 local $^W;
4141ef59
JP
34 *{$class.'::declare'} = \&{$CLASS.'::declare'};
35 *{$class.'::qv'} = \&{$CLASS.'::qv'};
f941e658
JP
36 }
37
38 my %args;
39 if (@_) { # any remaining terms are arguments
40 map { $args{$_} = 1 } @_
41 }
42 else { # no parameters at all on use line
5027b3af 43 %args =
f941e658
JP
44 (
45 qv => 1,
46 'UNIVERSAL::VERSION' => 1,
47 );
48 }
91152fc1 49
f941e658 50 my $callpkg = caller();
5027b3af 51
f941e658 52 if (exists($args{declare})) {
5027b3af 53 *{$callpkg.'::declare'} =
f941e658
JP
54 sub {return $class->declare(shift) }
55 unless defined(&{$callpkg.'::declare'});
56 }
57
58 if (exists($args{qv})) {
61a0cb1c 59 *{$callpkg.'::qv'} =
f941e658 60 sub {return $class->qv(shift) }
61a0cb1c 61 unless defined(&{$callpkg.'::qv'});
f941e658 62 }
c0b17f21 63
4141ef59
JP
64 if (exists($args{'UNIVERSAL::VERSION'})) {
65 local $^W;
66 *UNIVERSAL::VERSION
67 = \&{$CLASS.'::_VERSION'};
68 }
69
f941e658 70 if (exists($args{'VERSION'})) {
4141ef59 71 *{$callpkg.'::VERSION'} = \&{$CLASS.'::_VERSION'};
61a0cb1c
JP
72 }
73
74 if (exists($args{'is_strict'})) {
4141ef59 75 *{$callpkg.'::is_strict'} = \&{$CLASS.'::is_strict'}
d54f8cf7 76 unless defined(&{$callpkg.'::is_strict'});
61a0cb1c
JP
77 }
78
79 if (exists($args{'is_lax'})) {
4141ef59 80 *{$callpkg.'::is_lax'} = \&{$CLASS.'::is_lax'}
d54f8cf7 81 unless defined(&{$callpkg.'::is_lax'});
f941e658 82 }
c8a14fb6 83}
a7ad731c 84
91152fc1 85
a7ad731c 861;