From: Dave Rolsky Date: Wed, 15 Jul 2009 14:35:07 +0000 (-0500) Subject: tidy new code from Goro X-Git-Tag: 0.90~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=812d58f9517c19217fd09da63a6a87d80c202f11;p=gitmo%2FClass-MOP.git tidy new code from Goro --- diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index b6b3f52..e605533 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -59,7 +59,7 @@ sub _new { my $class = shift; return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $options = @_ == 1 ? $_[0] : {@_}; diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 5e6992e..d01da0f 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -10,7 +10,7 @@ use Class::MOP::Method::Accessor; use Class::MOP::Method::Constructor; use Carp 'confess'; -use Scalar::Util 'blessed', 'weaken'; +use Scalar::Util 'blessed', 'reftype', 'weaken'; use Sub::Name 'subname'; use Devel::GlobalDestruction 'in_global_destruction'; @@ -107,8 +107,9 @@ sub _construct_class_instance { sub _new { my $class = shift; + return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $options = @_ == 1 ? $_[0] : {@_}; @@ -388,7 +389,7 @@ sub _construct_instance { # NOTE: # this will only work for a HASH instance type if ($class->is_anon_class) { - (Scalar::Util::reftype($instance) eq 'HASH') + (reftype($instance) eq 'HASH') || confess "Currently only HASH based instances are supported with instance of anon-classes"; # NOTE: # At some point we should make this official @@ -722,12 +723,13 @@ sub alias_method { shift->add_method(@_); } -sub _code_is_mine{ - my($self, $code) = @_; - my($code_package, $code_name) = Class::MOP::get_code_info($code); - return $code_package - && $code_package eq $self->name - || ($code_package eq 'constant' && $code_name eq '__ANON__'); +sub _code_is_mine { + my ( $self, $code ) = @_; + + my ( $code_package, $code_name ) = Class::MOP::get_code_info($code); + + return $code_package && $code_package eq $self->name + || ( $code_package eq 'constant' && $code_name eq '__ANON__' ); } sub has_method { @@ -751,13 +753,14 @@ sub get_method { type => 'CODE', }); - if (!($method_object && $method_object->body == ($code || 0))){ - if ($code && $self->_code_is_mine($code)) { - $method_object = $method_map->{$method_name} = $self->wrap_method_body( - body => $code, - name => $method_name, - associated_metaclass => $self, - ); + unless ( $method_object && $method_object->body == ( $code || 0 ) ) { + if ( $code && $self->_code_is_mine($code) ) { + $method_object = $method_map->{$method_name} + = $self->wrap_method_body( + body => $code, + name => $method_name, + associated_metaclass => $self, + ); } else { delete $method_map->{$method_name}; diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index 112a038..3b6d025 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -43,8 +43,9 @@ sub wrap { sub _new { my $class = shift; + return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $params = @_ == 1 ? $_[0] : {@_}; diff --git a/lib/Class/MOP/Method/Accessor.pm b/lib/Class/MOP/Method/Accessor.pm index 4d0aa8f..59eb20c 100644 --- a/lib/Class/MOP/Method/Accessor.pm +++ b/lib/Class/MOP/Method/Accessor.pm @@ -45,7 +45,7 @@ sub _new { my $class = shift; return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $params = @_ == 1 ? $_[0] : {@_}; diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index 8382286..c1ac2b3 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -38,8 +38,9 @@ sub new { sub _new { my $class = shift; + return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $params = @_ == 1 ? $_[0] : {@_}; diff --git a/lib/Class/MOP/Module.pm b/lib/Class/MOP/Module.pm index 84e78ad..5755c5d 100644 --- a/lib/Class/MOP/Module.pm +++ b/lib/Class/MOP/Module.pm @@ -13,13 +13,14 @@ our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Package'; -sub _new{ +sub _new { my $class = shift; return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $params = @_ == 1 ? $_[0] : {@_}; return bless { + # from Class::MOP::Package package => $params->{package}, namespace => \undef, diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index aa98736..358b39f 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -4,7 +4,7 @@ package Class::MOP::Package; use strict; use warnings; -use Scalar::Util 'blessed'; +use Scalar::Util 'blessed', 'reftype'; use Carp 'confess'; our $VERSION = '0.89'; @@ -58,8 +58,9 @@ sub reinitialize { sub _new { my $class = shift; + return Class::MOP::Class->initialize($class)->new_object(@_) - if $class ne __PACKAGE__; + if $class ne __PACKAGE__; my $params = @_ == 1 ? $_[0] : {@_}; @@ -152,29 +153,31 @@ sub remove_package_glob { # ... these functions deal with stuff on the namespace level sub has_package_symbol { - my ($self, $variable) = @_; + my ( $self, $variable ) = @_; - my ($name, $sigil, $type) = ref $variable eq 'HASH' + my ( $name, $sigil, $type ) + = ref $variable eq 'HASH' ? @{$variable}{qw[name sigil type]} : $self->_deconstruct_variable_name($variable); - + my $namespace = $self->namespace; - - return 0 unless exists $namespace->{$name}; - + + return 0 unless exists $namespace->{$name}; + my $entry_ref = \$namespace->{$name}; - if (ref($entry_ref) eq 'GLOB') { - if ($type eq 'SCALAR') { - return defined(${ *{$entry_ref}{SCALAR} }); + if ( reftype($entry_ref) eq 'GLOB' ) { + if ( $type eq 'SCALAR' ) { + return defined( ${ *{$entry_ref}{SCALAR} } ); } else { - return defined(*{$entry_ref}{$type}); + return defined( *{$entry_ref}{$type} ); } - } - else { - # a symbol table entry can be -1 (stub), string (stub with prototype), - # or reference (constant) - return $type eq 'CODE'; + } + else { + + # a symbol table entry can be -1 (stub), string (stub with prototype), + # or reference (constant) + return $type eq 'CODE'; } } @@ -193,15 +196,15 @@ sub get_package_symbol { my $entry_ref = \$namespace->{$name}; - if (ref($entry_ref) eq 'GLOB') { + if ( ref($entry_ref) eq 'GLOB' ) { return *{$entry_ref}{$type}; } - else{ - if($type eq 'CODE'){ + else { + if ( $type eq 'CODE' ) { no strict 'refs'; - return \&{$self->name . '::' . $name}; + return \&{ $self->name . '::' . $name }; } - else{ + else { return undef; } }