summaryrefslogtreecommitdiff
path: root/scripts/Dpkg/Version.pm
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2013-02-10 13:18:28 +0100
committerGuillem Jover <guillem@debian.org>2013-07-08 00:57:38 +0200
commitea422eb8649dd15a3f5f2994af8e57c7c2e1e465 (patch)
tree7a7dbe494a5a54a6dffe75ca3d66fff55c9f01a4 /scripts/Dpkg/Version.pm
parente8950d7e2d4a58f96c74782825e2edf7ceb583ca (diff)
downloaddpkg-ea422eb8649dd15a3f5f2994af8e57c7c2e1e465.tar.gz
Dpkg: Move epoch-less or revision-less output logic to Dpkg::Version
Instead of doing the magic of generating a version string without epoch and revision and a version string without epoch in Dpkg::Source::Package, extend Dpkg::Version's as_string function to support generating that string. Based-on-patch-by: Bernhard R. Link <brlink@debian.org> Signed-off-by: Guillem Jover <guillem@debian.org>
Diffstat (limited to 'scripts/Dpkg/Version.pm')
-rw-r--r--scripts/Dpkg/Version.pm37
1 files changed, 31 insertions, 6 deletions
diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm
index 38830d9dc..82a393680 100644
--- a/scripts/Dpkg/Version.pm
+++ b/scripts/Dpkg/Version.pm
@@ -21,7 +21,7 @@ package Dpkg::Version;
use strict;
use warnings;
-our $VERSION = '1.00';
+our $VERSION = '1.01';
use Dpkg::ErrorHandling;
use Dpkg::Gettext;
@@ -43,7 +43,7 @@ use constant {
use overload
'<=>' => \&comparison,
'cmp' => \&comparison,
- '""' => \&as_string,
+ '""' => sub { return $_[0]->as_string(); },
'bool' => sub { return $_[0]->as_string() if $_[0]->is_valid(); },
'fallback' => 1;
@@ -166,18 +166,37 @@ sub comparison {
return version_compare_part($a->revision(), $b->revision());
}
-=item "$v", $v->as_string()
+=item "$v", $v->as_string(), $v->as_string(%options)
+
+Accepts an optional option hash reference, affecting the string conversion.
+
+Options:
+
+=over 8
+
+=item omit_epoch (defaults to 0)
+
+Omit the epoch, if present, in the output string.
+
+=item omit_revision (defaults to 0)
+
+Omit the revision, if present, in the output string.
+
+=back
Returns the string representation of the version number.
=cut
sub as_string {
- my ($self) = @_;
+ my ($self, %opts) = @_;
+ my $no_epoch = $opts{omit_epoch} || $self->{no_epoch};
+ my $no_revision = $opts{omit_revision} || $self->{no_revision};
+
my $str = '';
- $str .= $self->{epoch} . ':' unless $self->{no_epoch};
+ $str .= $self->{epoch} . ':' unless $no_epoch;
$str .= $self->{version};
- $str .= '-' . $self->{revision} unless $self->{no_revision};
+ $str .= '-' . $self->{revision} unless $no_revision;
return $str;
}
@@ -395,6 +414,12 @@ sub version_check($) {
=back
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New argument: Accept an options argument in $v->as_string().
+
=head1 AUTHOR
Don Armstrong <don@donarmstrong.com>, Colin Watson