From: Yuval Kogman Date: Sat, 9 Aug 2008 08:16:52 +0000 (+0000) Subject: make initialize() and create() consistent WRT package arg X-Git-Tag: 0_64_01~60 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=99b84658f57dd686b4c936bfd0e5ebe7a4efef3f;p=gitmo%2FClass-MOP.git make initialize() and create() consistent WRT package arg --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 479fc78..a3eacb1 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -19,12 +19,18 @@ use base 'Class::MOP::Module'; # Creation sub initialize { - my $class = shift; - my $package_name = shift; + my ( $class, @args ) = @_; + + unshift @args, 'package' if @args % 2 == 1; + + my (%options) = @args; + my $package_name = $options{package}; + (defined $package_name && $package_name && !blessed($package_name)) || confess "You must pass a package name and it cannot be blessed"; + return Class::MOP::get_metaclass_by_name($package_name) - || $class->construct_class_instance('package' => $package_name, @_); + || $class->construct_class_instance(%options); } sub reinitialize { @@ -228,10 +234,10 @@ sub check_metaclass_compatability { sub create { my ( $class, @args ) = @_; - unshift @args, 'name' if @args % 2 == 1; + unshift @args, 'package' if @args % 2 == 1; my (%options) = @args; - my $package_name = $options{name}; + my $package_name = $options{package}; (defined $package_name && $package_name) || confess "You must pass a package name"; diff --git a/t/003_methods.t b/t/003_methods.t index 26e6389..6580464 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -205,7 +205,7 @@ is_deeply( # ... test our class creator my $Bar = Class::MOP::Class->create( - name => 'Bar', + package => 'Bar', superclasses => [ 'Foo' ], methods => { foo => sub { 'Bar::foo' },