From: gfx Date: Tue, 22 Sep 2009 08:22:24 +0000 (+0900) Subject: Fix the timing triggers are invoked X-Git-Tag: 0.32~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53c495ce524c95ee0fc1ee13f20edeeb382ef89f;p=gitmo%2FMouse.git Fix the timing triggers are invoked --- diff --git a/Changes b/Changes index 7f31a1c..930ce5c 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ Revision history for Mouse * Fix Mouse::Util::find_meta() and Mouse::Util::does_role() (gfx) + * Fix the timing triggers are invoked (gfx) + * Implement confliction checks in roles * work around create() and create_anon() in Mouse::Meta::Role diff --git a/Makefile.PL b/Makefile.PL index 4fb0040..20396d5 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -91,8 +91,8 @@ sub create_moose_compatibility_test { close $rfh; $s; }; - $src =~ s/Mouse::is_class_loaded/Class::MOP::is_class_loaded/g; - $src =~ s/Mouse::load_class/Class::MOP::load_class/g; + $src =~ s/Mouse::(?:Util::)?is_class_loaded/Class::MOP::is_class_loaded/g; + $src =~ s/Mouse::(?:Util::)?load_class/Class::MOP::load_class/g; $src =~ s/Mouse/Moose/g; $src; }; diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 7084439..9ede6f8 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -119,6 +119,8 @@ sub new_object { my $instance = bless {}, $self->name; + my @triggers_queue; + foreach my $attribute ($self->get_all_attributes) { my $from = $attribute->init_arg; my $key = $attribute->name; @@ -134,7 +136,7 @@ sub new_object { if ref($instance->{$key}) && $attribute->is_weak_ref; if ($attribute->has_trigger) { - $attribute->trigger->($instance, $args{$from}); + push @triggers_queue, [ $attribute->trigger, $args{$from} ]; } } else { @@ -165,6 +167,12 @@ sub new_object { } } } + + foreach my $trigger_and_value(@triggers_queue){ + my($trigger, $value) = @{$trigger_and_value}; + $trigger->($instance, $value); + } + return $instance; } diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index d205492..cff5fc3 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -26,7 +26,7 @@ sub generate_constructor_method_inline { ... local $@; - # warn $code; + #warn $code; my $res = eval $code; die $@ if $@; $res; @@ -61,20 +61,20 @@ sub _generate_processattrs { } $code .= " \$attrs[$index]->verify_type_constraint_error( - '$key', \$value, \$attrs[$index]->type_constraint + q{$key}, \$value, \$attrs[$index]->type_constraint ) } "; } - $code .= "\$instance->{'$key'} = \$value;\n"; + $code .= "\$instance->{q{$key}} = \$value;\n"; if ($attr->is_weak_ref) { - $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n"; + $code .= "Scalar::Util::weaken( \$instance->{q{$key}} ) if ref( \$value );\n"; } if ($attr->has_trigger) { - $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value );\n"; + $code .= "push \@triggers, [\$attrs[$index]->{trigger}, \$value];\n"; } $code .= "\n} else {\n"; @@ -117,15 +117,15 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { $code .= "{ unless (\$attrs[$index]->{type_constraint}->check(\$value)) { - \$attrs[$index]->verify_type_constraint_error('$key', \$value, \$attrs[$index]->type_constraint) + \$attrs[$index]->verify_type_constraint_error(q{$key}, \$value, \$attrs[$index]->type_constraint) } }"; } - $code .= "\$instance->{'$key'} = \$value;\n"; + $code .= "\$instance->{q{$key}} = \$value;\n"; if ($attr->is_weak_ref) { - $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n"; + $code .= "Scalar::Util::weaken( \$instance->{q{$key}} ) if ref( \$value );\n"; } } } @@ -138,7 +138,7 @@ sub _generate_processattrs { push @res, $code; } - return join "\n", @res; + return join "\n", q{my @triggers;}, @res, q{$_->[0]->($instance, $_->[1]) for @triggers;}; } sub _generate_BUILDARGS { diff --git a/t/200_examples/001_example.t b/t/200_examples/001_example.t index b4606c4..58264b0 100644 --- a/t/200_examples/001_example.t +++ b/t/200_examples/001_example.t @@ -3,11 +3,17 @@ use strict; use warnings; -use Test::More tests => 20; +use Test::More; +BEGIN{ + if(eval{ require Class::Method::Modifiers::Fast } || eval{ require Class::Method::Modifiers }){ + plan tests => 20; + } + else{ + plan skip_all => 'This test requires Class::Method::Modifiers(::Fast)?'; + } +} use Test::Exception; - - ## Roles {