From: gfx Date: Sun, 26 Sep 2010 02:28:53 +0000 (+0900) Subject: Fix inlined method generations X-Git-Tag: 0.74~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68ad9d66d7f920d653bdf04d0880b0fdc87cc3c5;p=gitmo%2FMouse.git Fix inlined method generations --- diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index 2c5920a..0a89c23 100644 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -1,6 +1,8 @@ package Mouse::Meta::Method::Accessor; use Mouse::Util qw(:meta); # enables strict and warnings +use constant _MOUSE_DEBUG => !!$ENV{MOUSE_DEBUG}; + sub _inline_slot{ my(undef, $self_var, $attr_name) = @_; return sprintf '%s->{q{%s}}', $self_var, $attr_name; @@ -123,7 +125,7 @@ sub _generate_accessor_any{ $accessor .= "return $slot;\n}\n"; - #print $accessor, "\n"; + warn $accessor if _MOUSE_DEBUG; my $code; my $e = do{ local $@; diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 29e1ba7..0d00168 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -1,6 +1,8 @@ package Mouse::Meta::Method::Constructor; use Mouse::Util qw(:meta); # enables strict and warnings +use constant _MOUSE_DEBUG => !!$ENV{MOUSE_DEBUG}; + sub _inline_slot{ my(undef, $self_var, $attr_name) = @_; return sprintf '%s->{q{%s}}', $self_var, $attr_name; @@ -16,8 +18,8 @@ sub _generate_constructor { my $initializer = $metaclass->{_initialize_object} ||= do { $class->_generate_initialize_object($metaclass); }; - my $source = sprintf(<<'EOT', __LINE__, __FILE__, $metaclass->name, $buildargs, $buildall); -#line %d %s + my $source = sprintf(<<'EOT', __FILE__, $metaclass->name, $buildargs, $buildall); +#line 1 "%s" package %s; sub { my $class = shift; @@ -32,7 +34,7 @@ sub _generate_constructor { return $instance; } EOT - #warn $source; + warn $source if _MOUSE_DEBUG; my $body; my $e = do{ local $@; @@ -167,8 +169,8 @@ sub _generate_initialize_object { push @res, q{$_->[0]->($instance, $_->[1]) for @triggers;}; } - my $source = sprintf <<'EOT', __LINE__, __FILE__, $metaclass->name, join "\n", @res; -#line %d %s + my $source = sprintf <<'EOT', __FILE__, $metaclass->name, join "\n", @res; +#line 1 "%s" package %s; sub { my($meta, $instance, $args, $is_cloning) = @_; @@ -176,7 +178,7 @@ sub _generate_initialize_object { return $instance; } EOT - warn $source if $ENV{MOUSE_DEBUG}; + warn $source if _MOUSE_DEBUG; my $body; my $e = do { local $@; diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index 8b50f82..713c5fb 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,39 +1,51 @@ package Mouse::Meta::Method::Destructor; use Mouse::Util qw(:meta); # enables strict and warnings +use constant _MOUSE_DEBUG => !!$ENV{MOUSE_DEBUG}; + sub _generate_destructor{ my (undef, $metaclass) = @_; my $demolishall = ''; for my $class ($metaclass->linearized_isa) { if (Mouse::Util::get_code_ref($class, 'DEMOLISH')) { - $demolishall .= sprintf "%s::DEMOLISH(\$self, \$Mouse::Util::in_global_destruction);\n", - $class, + $demolishall .= ' ' . $class + . '::DEMOLISH($self, $Mouse::Util::in_global_destruction);' + . "\n", } } - my $name = $metaclass->name; - my $source = sprintf(<<'EOT', __LINE__, __FILE__, $name, $demolishall); -#line %d %s - package %s; - sub { - my $self = shift; - return $self->Mouse::Object::DESTROY() - if ref($self) ne __PACKAGE__; + if($demolishall) { + $demolishall = sprintf <<'EOT', $demolishall; my $e = do{ local $?; local $@; eval{ - # demolishall %s; }; $@; }; no warnings 'misc'; die $e if $e; # rethrow +EOT + } + + my $name = $metaclass->name; + my $source = sprintf(<<'EOT', __FILE__, $name, $demolishall); +#line 1 "%s" + package %s; + sub { + my($self) = @_; + return $self->Mouse::Object::DESTROY() + if ref($self) ne __PACKAGE__; + # DEMOLISHALL + %s; + return; } EOT + warn $source if _MOUSE_DEBUG; + my $code; my $e = do{ local $@;