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 as described in L<http://devmanual.gentoo.org/ebuild-writing/file-format/index.html>.
27 '<=>' => \&_spaceship,
31 my $int_rx = qr/[0-9]+/;
32 my $positive_int_rx = qr/0*[1-9][0-9]*/;
33 my $letter_rx = qr/[a-zA-Z]/;
34 my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/o;
36 my @suffixes = qw(alpha beta pre rc normal p);
37 my $suffix_rx = join '|', grep !/^normal$/, @suffixes;
38 $suffix_rx = qr/(?:$suffix_rx)/o;
41 $dotted_num_rx $letter_rx?
42 (?:_$suffix_rx$positive_int_rx?)*
43 (?:-r$positive_int_rx)?
46 my $capturing_version_rx = qr{
47 ($dotted_num_rx) ($letter_rx)?
48 ((?:_$suffix_rx$positive_int_rx?)*)
49 (?:-r($positive_int_rx))?
54 =head2 C<new $vstring>
56 Creates a new L<CPANPLUS::Dist::Gentoo::Version> object from the version string C<$vstring>.
62 $class = ref($class) || $class;
65 if (defined $vstring) {
66 $vstring =~ s/^[._]+//g;
67 $vstring =~ s/[._]+$//g;
69 if ($vstring =~ /^$capturing_version_rx$/o) {
72 version => [ split /\.+/, $1 ],
74 suffixes => [ map /_($suffix_rx)($positive_int_rx)?/go, $3 ],
80 Carp::croak("Couldn't parse version string '$vstring'");
84 Carp::croak('You must specify a version string');
89 @parts = qw/version letter suffixes revision/;
90 eval "sub $_ { \$_[0]->{$_} }" for @parts;
95 Read-only accessor for the C<version> part of the version object.
99 Read-only accessor for the C<letter> part of the version object.
103 Read-only accessor for the C<suffixes> part of the version object.
107 Read-only accessor for the C<revision> part of the version object.
111 my %suffix_grade = do {
113 map { $_ => ++$i } @suffixes;
117 my ($v1, $v2, $r) = @_;
119 unless (Scalar::Util::blessed($v2) and $v2->isa(__PACKAGE__)) {
123 ($v1, $v2) = ($v2, $v1) if $r;
126 my @a = @{ $v1->version };
127 my @b = @{ $v2->version };
130 my $x = shift(@a) || 0;
131 my $y = shift(@b) || 0;
138 my ($l1, $l2) = map { defined() ? ord : 0 } map $_->letter, $v1, $v2;
145 my @a = @{ $v1->suffixes };
146 my @b = @{ $v2->suffixes };
149 my $x = $suffix_grade{ shift(@a) || 'normal' };
150 my $y = $suffix_grade{ shift(@b) || 'normal' };
162 my ($r1, $r2) = map { defined() ? $_ : 0 } map $_->revision, $v1, $v2;
174 my ($version, $letter, $suffixes, $revision) = map $v->$_, @parts;
175 my @suffixes = @$suffixes;
177 $version = join '.', @$version;
178 $version .= $letter if defined $letter;
179 while (my @suffix = splice @suffixes, 0, 2) {
182 $version .= "_$s" . (defined $n ? $n : '');
184 $version .= "-r$revision" if defined $revision;
191 This class provides overloaded methods for numerical comparison and strigification.
195 L<CPANPLUS::Dist::Gentoo>.
199 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
201 You can contact me by mail or on C<irc.perl.org> (vincent).
205 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>.
206 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
210 You can find documentation for this module with the perldoc command.
212 perldoc CPANPLUS::Dist::Gentoo
214 =head1 COPYRIGHT & LICENSE
216 Copyright 2009,2010 Vincent Pit, all rights reserved.
218 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
222 1; # End of CPANPLUS::Dist::Gentoo::Version