1 package CPANPLUS::Dist::Gentoo::Version;
8 CPANPLUS::Dist::Gentoo::Version - Gentoo version object.
16 our $VERSION = '0.10';
20 This class models Gentoo versions.
27 '<=>' => \&_spaceship,
31 my $int_rx = qr/[0-9]+/;
32 my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/o;
34 our $version_rx = qr/$dotted_num_rx(?:_p$dotted_num_rx)?(?:-r$int_rx)?/o;
38 =head2 C<new $vstring>
40 Creates a new L<CPANPLUS::Dist::Gentoo::Version> object from the version string C<$vstring>.
46 $class = ref($class) || $class;
49 if (defined $vstring) {
50 $vstring =~ s/^[._]+//g;
51 $vstring =~ s/[._]+$//g;
52 if ($vstring =~ /^($dotted_num_rx)(?:_p($dotted_num_rx))?(?:-r($int_rx))?$/o){
55 version => [ split /\.+/, $1 ],
56 patch => [ defined $2 ? (split /\.+/, $2) : () ],
57 revision => [ defined $3 ? $3 : () ],
63 Carp::croak("Couldn't parse version string '$vstring'");
68 @parts = qw/version patch revision/;
69 eval "sub $_ { \$_[0]->{$_} }" for @parts;
74 Read-only accessor for the C<version> part of the version object.
78 Read-only accessor for the C<patch> part of the version object.
82 Read-only accessor for the C<revision> part of the version object.
87 my ($v1, $v2, $r) = @_;
89 unless (Scalar::Util::blessed($v2) and $v2->isa(__PACKAGE__)) {
93 ($v1, $v2) = ($v2, $v1) if $r;
99 my $x = shift(@a) || 0;
100 my $y = shift(@b) || 0;
112 my ($version, $patch, $revision) = map $v->$_, @parts;
114 $version = join '.', @$version;
115 $version .= '_p' . join('.', @$patch) if @$patch;
116 $version .= '-r' . join('.', @$revision) if @$revision;
123 This class provides overloaded methods for numerical comparison and strigification.
127 L<CPANPLUS::Dist::Gentoo>.
131 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
133 You can contact me by mail or on C<irc.perl.org> (vincent).
137 Please report any bugs or feature requests to C<bug-cpanplus-dist-gentoo at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANPLUS-Dist-Gentoo>.
138 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
142 You can find documentation for this module with the perldoc command.
144 perldoc CPANPLUS::Dist::Gentoo
146 =head1 COPYRIGHT & LICENSE
148 Copyright 2009,2010 Vincent Pit, all rights reserved.
150 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
154 1; # End of CPANPLUS::Dist::Gentoo::Version