diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2011-08-31 10:11:59 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2011-08-31 10:11:59 +0000 |
commit | e64875364b75855da7789df260242c3156d50baf (patch) | |
tree | b7b34f132b5a7b51c5cdf60a2a98c354eec7259d /usr.sbin/pkg_add | |
parent | 48d39031df987b97af31bab1438a2f6322fddbcb (diff) |
versionspec stuff belongs in PkgSpec, not PackageName
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageName.pm | 83 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgSpec.pm | 75 |
2 files changed, 71 insertions, 87 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm index 7b8adaec5cb..9e871a5b890 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageName.pm,v 1.50 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: PackageName.pm,v 1.51 2011/08/31 10:11:58 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -323,87 +323,6 @@ sub has_issues } } -package OpenBSD::PackageName::versionspec; -our @ISA = qw(OpenBSD::PackageName::version); - -my $ops = { - '<' => 'lt', - '<=' => 'le', - '>' => 'gt', - '>=' => 'ge', - '=' => 'eq' -}; - -sub from_string -{ - my ($class, $s) = @_; - my ($op, $version) = ('=', $s); - if ($s =~ m/^(\>\=|\>|\<\=|\<|\=)(.*)$/) { - ($op, $version) = ($1, $2); - } - bless $class->SUPER::from_string($version), - "OpenBSD::PackageName::version::$ops->{$op}"; -} - -sub pnum_compare -{ - my ($spec, $b) = @_; - if (!defined $spec->{p}) { - return 0; - } else { - return $spec->SUPER::pnum_compare($b); - } -} - -sub is_exact -{ - return 0; -} -package OpenBSD::PackageName::version::lt; -our @ISA = qw(OpenBSD::PackageName::versionspec); -sub match -{ - my ($self, $b) = @_; - -$self->compare($b) >= 0 ? 0 : 1; -} - -package OpenBSD::PackageName::version::le; -our @ISA = qw(OpenBSD::PackageName::versionspec); -sub match -{ - my ($self, $b) = @_; - -$self->compare($b) <= 0 ? 1 : 0; -} - -package OpenBSD::PackageName::version::gt; -our @ISA = qw(OpenBSD::PackageName::versionspec); -sub match -{ - my ($self, $b) = @_; - -$self->compare($b) > 0 ? 1 : 0; -} - -package OpenBSD::PackageName::version::ge; -our @ISA = qw(OpenBSD::PackageName::versionspec); -sub match -{ - my ($self, $b) = @_; - -$self->compare($b) >= 0 ? 1 : 0; -} - -package OpenBSD::PackageName::version::eq; -our @ISA = qw(OpenBSD::PackageName::versionspec); -sub match -{ - my ($self, $b) = @_; - -$self->compare($b) == 0 ? 1 : 0; -} - -sub is_exact -{ - return 1; -} - package OpenBSD::PackageName::Stem; sub to_string { diff --git a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm index 2ce2d592923..bb79057704a 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PkgSpec.pm,v 1.37 2011/07/12 10:22:29 espie Exp $ +# $OpenBSD: PkgSpec.pm,v 1.38 2011/08/31 10:11:58 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -80,18 +80,83 @@ sub match } package OpenBSD::PkgSpec::versionspec; +our @ISA = qw(OpenBSD::PackageName::version); +my $ops = { + '<' => 'lt', + '<=' => 'le', + '>' => 'gt', + '>=' => 'ge', + '=' => 'eq' +}; + sub new { my ($class, $s) = @_; - my $spec = OpenBSD::PackageName::versionspec->from_string($s); - bless \$spec, $class; + my ($op, $version) = ('=', $s); + if ($s =~ m/^(\>\=|\>|\<\=|\<|\=)(.*)$/) { + ($op, $version) = ($1, $2); + } + return "OpenBSD::PkgSpec::version::$ops->{$op}"->from_string($version); } +sub pnum_compare +{ + my ($self, $b) = @_; + if (!defined $self->{p}) { + return 0; + } else { + return $self->SUPER::pnum_compare($b); + } +} + +sub is_exact +{ + return 0; +} + +package OpenBSD::PkgSpec::version::lt; +our @ISA = qw(OpenBSD::PkgSpec::versionspec); sub match { - my ($self, $name) = @_; + my ($self, $b) = @_; + -$self->compare($b->{version}) < 0 ? 1 : 0; +} - return $$self->match($name->{version}); +package OpenBSD::PkgSpec::version::le; +our @ISA = qw(OpenBSD::PkgSpec::versionspec); +sub match +{ + my ($self, $b) = @_; + -$self->compare($b->{version}) <= 0 ? 1 : 0; +} + +package OpenBSD::PkgSpec::version::gt; +our @ISA = qw(OpenBSD::PkgSpec::versionspec); +sub match +{ + my ($self, $b) = @_; + -$self->compare($b->{version}) > 0 ? 1 : 0; +} + +package OpenBSD::PkgSpec::version::ge; +our @ISA = qw(OpenBSD::PkgSpec::versionspec); +sub match +{ + my ($self, $b) = @_; + -$self->compare($b->{version}) >= 0 ? 1 : 0; +} + +package OpenBSD::PkgSpec::version::eq; +our @ISA = qw(OpenBSD::PkgSpec::versionspec); +sub match +{ + my ($self, $b) = @_; + -$self->compare($b->{version}) == 0 ? 1 : 0; +} + +sub is_exact +{ + return 1; } package OpenBSD::PkgSpec::badspec; |