From: gfx Date: Fri, 25 Sep 2009 03:24:36 +0000 (+0900) Subject: Tidy X-Git-Tag: 0.35~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53875581c2449e237cc1135b8c2cf1674a874aed;p=gitmo%2FMouse.git Tidy --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index eccc881..ec752cb 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -5,7 +5,7 @@ use warnings; use Carp (); use Scalar::Util qw(weaken); -use Mouse::Util; +use Mouse::Util qw(:meta); use Mouse::Meta::TypeConstraint; use Mouse::Meta::Method::Accessor; @@ -153,16 +153,6 @@ sub new { return $instance } -sub does { - my ($self, $role_name) = @_; - my $meta = Mouse::Meta::Class->initialize(ref($self) || $self); - - (defined $role_name) - || $meta->throw_error("You must supply a role name to does()"); - - return $meta->does_role($role_name); -}; - # readers sub name { $_[0]->{name} } diff --git a/lib/Mouse/Meta/Method.pm b/lib/Mouse/Meta/Method.pm index a423012..9c0b5e3 100755 --- a/lib/Mouse/Meta/Method.pm +++ b/lib/Mouse/Meta/Method.pm @@ -2,6 +2,8 @@ package Mouse::Meta::Method; use strict; use warnings; +use Mouse::Util qw(:meta); + use overload '&{}' => 'body', fallback => 1, diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 58e712a..9fd52b9 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -5,7 +5,7 @@ use warnings; use Carp (); use Scalar::Util qw/blessed weaken/; -use Mouse::Util qw/get_code_info not_supported load_class/; +use Mouse::Util qw/get_code_info not_supported load_class :meta/; { my %METACLASS_CACHE; @@ -46,8 +46,6 @@ use Mouse::Util qw/get_code_info not_supported load_class/; } -sub meta{ Mouse::Meta::Class->initialize(ref $_[0] || $_[0]) } - sub _new{ Carp::croak("Mouse::Meta::Module is an abstract class") } sub name { $_[0]->{package} } diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 30b0f06..3405a18 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -7,7 +7,7 @@ use overload '""' => sub { shift->{name} }, # stringify to tc name use Carp (); -use Mouse::Util (); +use Mouse::Util qw(:meta); sub new { my $class = shift; diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index 16846f5..89bd8ca 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -2,7 +2,7 @@ package Mouse::Object; use strict; use warnings; -use Mouse::Util; +use Mouse::Util qw(does dump); sub new { my $class = shift; @@ -66,25 +66,6 @@ sub DEMOLISHALL { return; } -sub dump { - my($self, $maxdepth) = @_; - - require 'Data/Dumper.pm'; # we don't want to create its namespace - my $dd = Data::Dumper->new([$self]); - $dd->Maxdepth(defined($maxdepth) ? $maxdepth : 2); - $dd->Indent(1); - return $dd->Dump(); -} - - -sub does { - my ($self, $role_name) = @_; - (defined $role_name) - || $self->meta->throw_error("You must supply a role name to does()"); - - return $self->meta->does_role($role_name); -}; - 1; __END__ diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 35c117d..01a9efc 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -20,9 +20,12 @@ our @EXPORT_OK = qw( get_code_info not_supported + + does meta dump ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, + meta => [qw(does meta dump)], ); # Moose::Util compatible utilities @@ -32,13 +35,14 @@ sub find_meta{ } sub does_role{ - my ($class_or_obj, $role) = @_; + my ($class_or_obj, $role_name) = @_; my $meta = Mouse::Meta::Module::class_of($class_or_obj); - return 0 unless defined $meta; - return 1 if $meta->does_role($role); - return 0; + (defined $role_name) + || ($meta || 'Mouse::Meta::Class')->throw_error("You must supply a role name to does()"); + + return defined($meta) && $meta->does_role($role_name); } @@ -145,7 +149,6 @@ sub load_first_existing_class { my @classes = @_ or return; - my $found; my %exceptions; for my $class (@classes) { my $e = _try_load_one_class($class); @@ -154,12 +157,11 @@ sub load_first_existing_class { $exceptions{$class} = $e; } else { - $found = $class; - last; + return $class; } } - return $found if $found; + # not found confess join( "\n", map { @@ -276,6 +278,9 @@ sub english_list { return join q{, }, @items, "and $tail"; } + +# common utilities + sub not_supported{ my($feature) = @_; @@ -285,6 +290,23 @@ sub not_supported{ Carp::confess("Mouse does not currently support $feature"); } +sub meta{ + return Mouse::Meta::Class->initialize($_[0]); +} + +sub dump { + my($self, $maxdepth) = @_; + + require 'Data/Dumper.pm'; # we don't want to create its namespace + my $dd = Data::Dumper->new([$self]); + $dd->Maxdepth(defined($maxdepth) ? $maxdepth : 2); + $dd->Indent(1); + return $dd->Dump(); +} + +sub does :method; +*does = \&does_role; # alias + 1; __END__