From: gfx Date: Tue, 23 Feb 2010 01:37:16 +0000 (+0900) Subject: Make Mouse::Util::load_class return the argument class name, which can remove several... X-Git-Tag: 0.50_04~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=637d4f17e6965551c032a3115dcbbb4d8e01fbf5 Make Mouse::Util::load_class return the argument class name, which can remove several temporary variables. --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 985f046..315eaa4 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -378,10 +378,8 @@ sub _canonicalize_handles { sub _make_delegation_method { my($self, $handle, $method_to_call) = @_; - my $delegator = $self->delegation_metaclass; - Mouse::Util::load_class($delegator); - - return $delegator->_generate_delegation($self, $handle, $method_to_call); + return Mouse::Util::load_class($self->delegation_metaclass) + ->_generate_delegation($self, $handle, $method_to_call); } sub throw_error{ diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index dd6a95d..84c36d5 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -247,17 +247,15 @@ sub make_immutable { $self->{strict_constructor} = $args{strict_constructor}; if ($args{inline_constructor}) { - my $c = $self->constructor_class; - Mouse::Util::load_class($c); $self->add_method($args{constructor_name} => - $c->_generate_constructor($self, \%args)); + Mouse::Util::load_class($self->constructor_class) + ->_generate_constructor($self, \%args)); } if ($args{inline_destructor}) { - my $c = $self->destructor_class; - Mouse::Util::load_class($c); $self->add_method(DESTROY => - $c->_generate_destructor($self, \%args)); + Mouse::Util::load_class($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/Module.pm b/lib/Mouse/Meta/Module.pm index 6c32c9d..7d2a1e9 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -1,5 +1,5 @@ package Mouse::Meta::Module; -use Mouse::Util qw/:meta get_code_package get_code_ref load_class not_supported/; # enables strict and warnings +use Mouse::Util qw/:meta get_code_package get_code_ref not_supported/; # enables strict and warnings use Carp (); use Scalar::Util (); @@ -130,10 +130,7 @@ sub get_method{ my($self, $method_name) = @_; if(my $code = $self->get_method_body($method_name)){ - my $method_metaclass = $self->method_metaclass; - load_class($method_metaclass); - - return $method_metaclass->wrap( + return Mouse::Util::load_class($self->method_metaclass)->wrap( body => $code, name => $method_name, package => $self->name, diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index edcd193..cd6297a 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -244,12 +244,12 @@ sub _try_load_one_class { return undef if $is_class_loaded_cache{$class} ||= is_class_loaded($class); - my $file = $class . '.pm'; - $file =~ s{::}{/}g; + $class =~ s{::}{/}g; + $class .= '.pm'; return do { local $@; - eval { require($file) }; + eval { require $class }; $@; }; } @@ -260,7 +260,7 @@ sub load_class { my $e = _try_load_one_class($class); Carp::confess "Could not load class ($class) because : $e" if $e; - return 1; + return $class; } sub is_class_loaded;