From: gfx Date: Wed, 7 Oct 2009 10:29:42 +0000 (+0900) Subject: More compatibility X-Git-Tag: 0.37_03~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=380e1cd7159fdf0efd57348736ca901825e1e4e8;p=gitmo%2FMouse.git More compatibility --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 1220d29..afc6f57 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -11,6 +11,9 @@ our @ISA = qw(Mouse::Meta::Module); sub method_metaclass() { 'Mouse::Meta::Method' } sub attribute_metaclass() { 'Mouse::Meta::Attribute' } +sub constructor_class() { 'Mouse::Meta::Method::Constructor' } +sub destructor_class() { 'Mouse::Meta::Method::Destructor' } + sub _construct_meta { my($class, %args) = @_; @@ -256,13 +259,13 @@ sub make_immutable { $self->{is_immutable}++; if ($args{inline_constructor}) { - # generate and install - Mouse::Meta::Method::Constructor->_generate_constructor_method($self, \%args); + $self->add_method($args{constructor_name} => + $self->constructor_class->_generate_constructor($self, \%args)); } if ($args{inline_destructor}) { - # generate and install - Mouse::Meta::Method::Destructor->_generate_destructor_method($self, \%args); + $self->add_method(DESTROY => + $self->destructor_class->_generate_destructor($self, \%args)); } # Moose's make_immutable returns true allowing calling code to skip setting an explicit true value diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index f6287db..97e1603 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -1,7 +1,7 @@ package Mouse::Meta::Method::Constructor; use Mouse::Util; # enables strict and warnings -sub _generate_constructor_method { +sub _generate_constructor { my ($class, $metaclass, $args) = @_; my $associated_metaclass_name = $metaclass->name; @@ -38,9 +38,7 @@ sub _generate_constructor_method { $@; }; die $e if $e; - - $metaclass->add_method($args->{constructor_name} => $code); - return; + return $code; } sub _generate_processattrs { diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index 783e6d3..7775a14 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -1,42 +1,38 @@ package Mouse::Meta::Method::Destructor; use Mouse::Util; # enables strict and warnings -sub _empty_destroy{ } +sub _empty_DESTROY{ } -sub _generate_destructor_method { - my ($class, $metaclass) = @_; +sub _generate_destructor{ + my (undef, $metaclass) = @_; - my $demolishall = do { - if ($metaclass->name->can('DEMOLISH')) { - my @code = (); - for my $class ($metaclass->linearized_isa) { - no strict 'refs'; - if (*{$class . '::DEMOLISH'}{CODE}) { - push @code, "${class}::DEMOLISH(\$self);"; - } - } - join "\n", @code; - } else { - $metaclass->add_method(DESTROY => \&_empty_destroy); - return; + if(!$metaclass->name->can('DEMOLISH')){ + return \&_empty_DESTROY; + } + + my $demolishall = ''; + for my $class ($metaclass->linearized_isa) { + no strict 'refs'; + if (*{$class . '::DEMOLISH'}{CODE}) { + $demolishall .= "${class}::DEMOLISH(\$self);\n"; } - }; + } - my $destructor_name = $metaclass->name . '::DESTROY'; my $source = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"..."; - sub $destructor_name \{ + sub { my \$self = shift; $demolishall; } ... + my $code; my $e = do{ local $@; - eval $source; + $code = eval $source; $@; }; die $e if $e; - return; + return $code; } 1;