diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-04-19 10:23:00 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-04-19 10:23:00 +0000 |
commit | cd16d39940b7a8677115c705bc0b51e1030dc677 (patch) | |
tree | 019b34b35308cdc718901962e3b840a55a06f977 | |
parent | 9f070ef69cab532420e05ecd8825e51aa48bd578 (diff) |
move Composite pattern (auto-visitor) into its own subclass
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index db3cb8fb17e..c314b705314 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.103 2010/04/05 16:07:10 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.104 2010/04/19 10:22:59 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -54,11 +54,38 @@ sub match $h->{$plist->fullpkgpath}; } +package OpenBSD::Composite; + +sub AUTOLOAD +{ + our $AUTOLOAD; + my $fullsub = $AUTOLOAD; + (my $sub = $fullsub) =~ s/.*:://o; + return if $sub eq 'DESTROY'; # special case + my $self = $_[0]; + # verify it makes sense + if ($self->element_class->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 ".ref($self); + } +} + package OpenBSD::PackingList; +our @ISA = qw(OpenBSD::Composite); use OpenBSD::PackingElement; use OpenBSD::PackageInfo; +sub element_class { "OpenBSD::PackingElement" } + sub new { my $class = shift; @@ -544,27 +571,6 @@ sub forget # convert call to $self->sub(@args) into $self->visit(sub, @args) -sub AUTOLOAD -{ - our $AUTOLOAD; - my $fullsub = $AUTOLOAD; - (my $sub = $fullsub) =~ s/.*:://o; - 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__; - } -} - sub signature { my $self = shift; |