1 package CPANPLUS::Dist::Gentoo::Version;
13 our $VERSION = '0.08';
16 my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/;
18 our $version_rx = qr/$dotted_num_rx(?:_p$dotted_num_rx)?(?:-r$int_rx)?/;
22 $class = ref($class) || $class;
25 if (defined $vstring) {
26 $vstring =~ s/^[._]+//g;
27 $vstring =~ s/[._]+$//g;
28 if ($vstring =~ /^($dotted_num_rx)(?:_p($dotted_num_rx))?(?:-r($int_rx))?$/) {
31 version => [ split /\.+/, $1 ],
32 patch => [ defined $2 ? (split /\.+/, $2) : () ],
33 revision => [ defined $3 ? $3 : () ],
39 Carp::croak("Couldn't parse version string '$vstring'");
44 @parts = qw/version patch revision/;
45 eval "sub $_ { \$_[0]->{$_} }" for @parts;
49 my ($v1, $v2, $r) = @_;
51 unless (Scalar::Util::blessed($v2) and $v2->isa(__PACKAGE__)) {
55 ($v1, $v2) = ($v2, $v1) if $r;
61 my $x = shift(@a) || 0;
62 my $y = shift(@b) || 0;
74 my ($version, $patch, $revision) = map $v->$_, @parts;
76 $version = join '.', @$version;
77 $version .= '_p' . join('.', @$patch) if @$patch;
78 $version .= '-r' . join('.', @$revision) if @$revision;