From: Yuval Kogman Date: Sat, 9 Aug 2008 05:51:12 +0000 (+0000) Subject: clean up metaclass::import X-Git-Tag: 0_64_01~62 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec21cb136b8d96f67395c0db77c408e8366f1a8a;p=gitmo%2FClass-MOP.git clean up metaclass::import --- diff --git a/lib/metaclass.pm b/lib/metaclass.pm index 49f57b1..f45769d 100644 --- a/lib/metaclass.pm +++ b/lib/metaclass.pm @@ -13,20 +13,22 @@ our $AUTHORITY = 'cpan:STEVAN'; use Class::MOP; sub import { - shift; - my $metaclass; - if (!defined($_[0]) || $_[0] =~ /^(attribute|method|instance)_metaclass/) { - $metaclass = 'Class::MOP::Class'; - } - else { - $metaclass = shift; - #make sure the custom metaclass gets loaded + my ( $class, @args ) = @_; + + unshift @args, "metaclass" if @args % 2 == 1; + my %options = @args; + + my $metaclass = delete $options{metaclass}; + + unless ( defined $metaclass ) { + $metaclass = "Class::MOP::Class"; + } else { Class::MOP::load_class($metaclass); - ($metaclass->isa('Class::MOP::Class')) - || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class"; } - my %options = @_; - + + ($metaclass->isa('Class::MOP::Class')) + || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class"; + # make sure the custom metaclasses get loaded foreach my $class (grep { /^(attribute|method|instance)_metaclass/