diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-01-19 14:26:25 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-01-19 14:26:25 +0000 |
commit | a413c4ef59396e1c3731c36bcdee63d898aa78b1 (patch) | |
tree | cd55c6975e0d11cfb69630c96171917d42830a23 | |
parent | 8b61ebf3622ec79a5fc04bc524bebc27d50a75cd (diff) |
move generic code to handle libspec in a new file, to clean up stuff
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/LibSpec.pm | 107 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 9 |
3 files changed, 117 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 17e59b271c1..7cf5b2e1567 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.58 2010/01/11 12:25:38 espie Exp $ +# $OpenBSD: Makefile,v 1.59 2010/01/19 14:26:24 espie Exp $ .include <bsd.own.mk> @@ -23,6 +23,7 @@ PACKAGES= \ OpenBSD/Handle.pm \ OpenBSD/IdCache.pm \ OpenBSD/Interactive.pm \ + OpenBSD/LibSpec.pm \ OpenBSD/Mtree.pm \ OpenBSD/OldLibs.pm \ OpenBSD/PackageInfo.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/LibSpec.pm b/usr.sbin/pkg_add/OpenBSD/LibSpec.pm new file mode 100644 index 00000000000..d586c24ab3a --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/LibSpec.pm @@ -0,0 +1,107 @@ +# ex:ts=8 sw=4: +# $OpenBSD: LibSpec.pm,v 1.1 2010/01/19 14:26:24 espie Exp $ +# +# Copyright (c) 2010 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +use strict; +use warnings; + +package OpenBSD::Library; + +package OpenBSD::LibSpec; + +sub new +{ + my ($class, $dir, $stem, $major, $minor) = @_; + $dir //= "lib"; + bless { + dir => $dir, stem => $stem, + major => $major, minor => $minor + }, $class; +} + +sub key +{ + my $self = shift; + return "$self->{dir}/$self->{stem}"; +} + +sub major +{ + my $self = shift; + return $self->{major}; +} + +sub minor +{ + my $self = shift; + return $self->{minor}; +} + +sub badspec +{ + "OpenBSD::LibSpec::BadSpec"; +} + +sub from_string +{ + my ($class, $string) = @_; + if (my ($stem, $major, $minor) = $string =~ m/^(.*)\.(\d+)\.(\d+)$/o) { + if ($stem =~ m/^(.*)\/([^\/]+)$/o) { + return $class->new($1, $2, $major, $minor); + } else { + return $class->new(undef, $stem, $major, $minor); + } + } else { + return $class->badspec->new($string); + } +} + +sub to_string +{ + my $self = shift; + my $s = join('.', $self->{stem}, $self->{major}, $self->{minor}); + + if ($self->{dir} ne 'lib') { + $s = "$self->{dir}/$s"; + } + return $s; +} + +sub is_valid +{ + return 1; +} +package OpenBSD::LibSpec::BadSpec; +our @ISA=qw(OpenBSD::LibSpec); + +sub to_string +{ + my $self = shift; + return $$self; +} + +sub new +{ + my ($class, $string) = @_; + bless \$string, $class; +} + +sub is_valid +{ + return 0; +} + +1; diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 3df5c079abf..9628941b901 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.172 2010/01/10 11:31:08 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.173 2010/01/19 14:26:24 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -951,6 +951,13 @@ sub add_digest &OpenBSD::PackingElement::FileBase::add_digest; } +OpenBSD::Auto::cache(spec, + sub { + my $self = shift; + + require OpenBSD::LibSpec; + return OpenBSD::LibSpec->from_string($self->name); + }); package OpenBSD::PackingElement::PkgPath; our @ISA=qw(OpenBSD::PackingElement::Meta); |