From: Yuval Kogman Date: Fri, 8 Aug 2008 22:32:07 +0000 (+0000) Subject: Accept fully named params to Class::MOP::Class::create X-Git-Tag: 0_64_01~73 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3976fb78d652db94c091ae2d6151045632d032ef;p=gitmo%2FClass-MOP.git Accept fully named params to Class::MOP::Class::create --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index ad0c98c..439ed84 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -226,17 +226,15 @@ sub check_metaclass_compatability { # creating classes with MOP ... sub create { - my $class = shift; - my $package_name = shift; + my ( $class, @args ) = @_; - (defined $package_name && $package_name) - || confess "You must pass a package name"; + unshift @args, 'name' if @args % 2 == 1; - (scalar @_ % 2 == 0) - || confess "You much pass all parameters as name => value pairs " . - "(I found an uneven number of params in \@_)"; + my (%options) = @args; + my $package_name = $options{name}; - my (%options) = @_; + (defined $package_name && $package_name) + || confess "You must pass a package name"; (ref $options{superclasses} eq 'ARRAY') || confess "You must pass an ARRAY ref of superclasses" @@ -261,6 +259,7 @@ sub create { my $meta = $class->initialize($package_name); + # FIXME totally lame $meta->add_method('meta' => sub { $class->initialize(blessed($_[0]) || $_[0]); }); diff --git a/t/003_methods.t b/t/003_methods.t index ebc5494..26e6389 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -205,13 +205,13 @@ is_deeply( # ... test our class creator my $Bar = Class::MOP::Class->create( - 'Bar' => ( - superclasses => [ 'Foo' ], - methods => { - foo => sub { 'Bar::foo' }, - bar => sub { 'Bar::bar' }, - } - )); + name => 'Bar', + superclasses => [ 'Foo' ], + methods => { + foo => sub { 'Bar::foo' }, + bar => sub { 'Bar::bar' }, + } +); isa_ok($Bar, 'Class::MOP::Class'); ok($Bar->has_method('foo'), '... Bar->has_method(foo)');