diff options
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 25 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pod/OpenBSD::PackingList.pod | 10 |
2 files changed, 33 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index 90c30cb9319..e81801e186a 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingList.pm,v 1.55 2007/04/15 10:17:29 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.56 2007/04/29 10:52:15 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -440,4 +440,27 @@ sub forget { } +# convert call to $self->sub(@args) into $self->visit(sub, @args) + +sub AUTOLOAD +{ + our $AUTOLOAD; + my $fullsub = $AUTOLOAD; + (my $sub = $fullsub) =~ s/.*:://; + return if $sub eq 'DESTROY'; # special case + # verify it makes sense + if (OpenBSD::PackingElement->can($sub)) { + no strict "refs"; + # create the sub to avoid regenerating further calls + *$fullsub = sub { + my $self = shift; + $self->visit($sub, @_); + }; + # and jump to it + goto &$fullsub; + } else { + die "Can't call $sub on ", __PACKAGE__; + } +} + 1; diff --git a/usr.sbin/pkg_add/pod/OpenBSD::PackingList.pod b/usr.sbin/pkg_add/pod/OpenBSD::PackingList.pod index 036a084d9fd..5c5794bf796 100644 --- a/usr.sbin/pkg_add/pod/OpenBSD::PackingList.pod +++ b/usr.sbin/pkg_add/pod/OpenBSD::PackingList.pod @@ -1,4 +1,4 @@ -$OpenBSD: OpenBSD::PackingList.pod,v 1.5 2005/09/19 09:30:28 espie Exp $ +$OpenBSD: OpenBSD::PackingList.pod,v 1.6 2007/04/29 10:52:15 espie Exp $ =head1 NAME @@ -34,6 +34,9 @@ OpenBSD::PackingList - C<pkg_add(1)> packing-list manipulations # processing packing-lists $p4->visit('method', @args); + # auto visit + $p4->method(@args); + # signatures if ($p3->signature() eq $p4->signature()) { } @@ -123,3 +126,8 @@ C<$plist-E<gt>pkgname()> retrieves a packing-list name (mandatory). C<$plist-E<gt>signature()> retrieves a packing-list full signature, composed of the package name and dependency information. +C<$plist-E<gt>visit($method, @args)> is a visitor pattern, calling +C<method(@args)> on each element of the packing-list in a specific order. + +As a feature, if C<OpenBSD::PackingElement-E<gt>can(method)>, +C<$plist-E<gt>method(@args)> will be turned into a visitor call automatically. |