From: Todd Hepler Date: Tue, 30 Sep 2008 15:32:31 +0000 (+0000) Subject: Class::MOP::Class::create() X-Git-Tag: 0.67~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34d049672b90d520d079a4f9d7199c7549c3900c;p=gitmo%2FClass-MOP.git Class::MOP::Class::create() - pass unused options to initialize() --- diff --git a/Changes b/Changes index 59e738f..203fc98 100644 --- a/Changes +++ b/Changes @@ -6,8 +6,10 @@ Revision history for Perl extension Class-MOP. so that we can get Perl to detect cycles before MRO::Compat spirals into an infinite loop (sartak) - Reported by Schwern, [rt.cpan.org #39001] + - In create(), pass unused options on to initialize() + - added test for this -0.66 +0.66 Sat September 20, 2008 !! This release has an incompatible change regarding !! introspection of a class's method with Class::MOP::Class !! diff --git a/MANIFEST b/MANIFEST index 311bd7a..8b140f7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -60,6 +60,7 @@ t/044_instance_metaclass_incompat_dyn.t t/045_metaclass_loads_classes.t t/046_rebless_instance.t t/047_rebless_with_extra_params.t +t/048_anon_class_create_init.t t/050_scala_style_mixin_composition.t t/060_instance.t t/061_instance_inline.t diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 59baa88..af1fb2d 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -274,7 +274,16 @@ sub create { eval $code; confess "creation of $package_name failed : $@" if $@; - my $meta = $class->initialize($package_name); + my (%initialize_options) = @args; + delete @initialize_options{qw( + package + superclasses + attributes + methods + version + authority + )}; + my $meta = $class->initialize( $package_name => %initialize_options ); # FIXME totally lame $meta->add_method('meta' => sub { diff --git a/t/048_anon_class_create_init.t b/t/048_anon_class_create_init.t new file mode 100644 index 0000000..f95ade0 --- /dev/null +++ b/t/048_anon_class_create_init.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +use Class::MOP; + +{ + package MyMeta; + use base 'Class::MOP::Class'; + sub initialize { + my $class = shift; + my ( $package, %options ) = @_; + ::cmp_ok( $options{foo}, 'eq', 'this', + 'option passed to initialize() on create_anon_class()' ); + return $class->SUPER::initialize( @_ ); + } + +} + +my $anon = MyMeta->create_anon_class( foo => 'this' ); +isa_ok( $anon, 'MyMeta' ); +