This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Grab latest changes from CPAN 0.9905
[perl5.git] / cpan / version / lib / version.pm
CommitLineData
c8d69e4a 1#!perl -w
a7ad731c
HS
2package version;
3
4141ef59 4use 5.005_05;
a7ad731c
HS
5use strict;
6
91152fc1 7use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
a7ad731c 8
4141ef59 9$VERSION = 0.9905;
a7ad731c
HS
10$CLASS = 'version';
11
4141ef59
JP
12{
13 local $SIG{'__DIE__'};
14 eval "use version::vxs $VERSION";
15 if ( $@ ) { # don't have the XS version installed
16 eval "use version::vpp $VERSION"; # don't tempt fate
17 die "$@" if ( $@ );
18 push @ISA, "version::vpp";
19 local $^W;
20 *version::qv = \&version::vpp::qv;
21 *version::declare = \&version::vpp::declare;
22 *version::_VERSION = \&version::vpp::_VERSION;
23 *version::vcmp = \&version::vpp::vcmp;
24 *version::new = \&version::vpp::new;
25 if ($] >= 5.009000) {
26 no strict 'refs';
27 *version::stringify = \&version::vpp::stringify;
28 *{'version::(""'} = \&version::vpp::stringify;
29 *{'version::(<=>'} = \&version::vpp::vcmp;
30 *version::parse = \&version::vpp::parse;
31 }
32 *version::is_strict = \&version::vpp::is_strict;
33 *version::is_lax = \&version::vpp::is_lax;
34 }
35 else { # use XS module
36 push @ISA, "version::vxs";
37 local $^W;
38 *version::declare = \&version::vxs::declare;
39 *version::qv = \&version::vxs::qv;
40 *version::_VERSION = \&version::vxs::_VERSION;
41 *version::vcmp = \&version::vxs::VCMP;
42 *version::new = \&version::vxs::new;
43 if ($] >= 5.009000) {
44 no strict 'refs';
45 *version::stringify = \&version::vxs::stringify;
46 *{'version::(""'} = \&version::vxs::stringify;
47 *{'version::(<=>'} = \&version::vxs::VCMP;
48 *version::parse = \&version::vxs::parse;
49 }
50 *version::is_strict = \&version::vxs::is_strict;
51 *version::is_lax = \&version::vxs::is_lax;
52 }
53}
91152fc1 54
c8a14fb6 55sub import {
c8a14fb6 56 no strict 'refs';
f941e658
JP
57 my ($class) = shift;
58
59 # Set up any derived class
4141ef59 60 unless ($class eq $CLASS) {
f941e658 61 local $^W;
4141ef59
JP
62 *{$class.'::declare'} = \&{$CLASS.'::declare'};
63 *{$class.'::qv'} = \&{$CLASS.'::qv'};
f941e658
JP
64 }
65
66 my %args;
67 if (@_) { # any remaining terms are arguments
68 map { $args{$_} = 1 } @_
69 }
70 else { # no parameters at all on use line
5027b3af 71 %args =
f941e658
JP
72 (
73 qv => 1,
74 'UNIVERSAL::VERSION' => 1,
75 );
76 }
91152fc1 77
f941e658 78 my $callpkg = caller();
5027b3af 79
f941e658 80 if (exists($args{declare})) {
5027b3af 81 *{$callpkg.'::declare'} =
f941e658
JP
82 sub {return $class->declare(shift) }
83 unless defined(&{$callpkg.'::declare'});
84 }
85
86 if (exists($args{qv})) {
61a0cb1c 87 *{$callpkg.'::qv'} =
f941e658 88 sub {return $class->qv(shift) }
61a0cb1c 89 unless defined(&{$callpkg.'::qv'});
f941e658 90 }
c0b17f21 91
4141ef59
JP
92 if (exists($args{'UNIVERSAL::VERSION'})) {
93 local $^W;
94 *UNIVERSAL::VERSION
95 = \&{$CLASS.'::_VERSION'};
96 }
97
f941e658 98 if (exists($args{'VERSION'})) {
4141ef59 99 *{$callpkg.'::VERSION'} = \&{$CLASS.'::_VERSION'};
61a0cb1c
JP
100 }
101
102 if (exists($args{'is_strict'})) {
4141ef59 103 *{$callpkg.'::is_strict'} = \&{$CLASS.'::is_strict'}
d54f8cf7 104 unless defined(&{$callpkg.'::is_strict'});
61a0cb1c
JP
105 }
106
107 if (exists($args{'is_lax'})) {
4141ef59 108 *{$callpkg.'::is_lax'} = \&{$CLASS.'::is_lax'}
d54f8cf7 109 unless defined(&{$callpkg.'::is_lax'});
f941e658 110 }
c8a14fb6 111}
a7ad731c 112
91152fc1 113
a7ad731c 1141;