X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil.pm;h=5f3df61f50c9486bc60d0fd00cb3c54514522bc4;hp=7ac2a08263001d537742448d1d4fa42f783003cb;hb=6a97bbdad44391f2a587165cb81fcf8aedc642ac;hpb=745220df2da2256a9bd2692ac585f39b35ed19df diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 7ac2a08..5f3df61 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -5,17 +5,22 @@ BEGIN{ # Because Mouse::Util is loaded first in all the Mouse sub-modules, # XS loader is placed here, not in Mouse.pm. - our $VERSION = '0.40_01'; + our $VERSION = '0.40_04'; my $need_pp = !!$ENV{MOUSE_PUREPERL}; if(!$need_pp && !exists $INC{'Mouse/PurePerl.pm'}){ local $@; - $need_pp = !eval{ + + # XXX: XSLoader tries to get the object path from caller's file name + # $hack_mouse_file fools its mechanism + + (my $hack_mouse_file = __FILE__) =~ s/.Util//; # .../Mouse/Util.pm -> .../Mouse.pm + $need_pp = !eval sprintf("#line %d %s\n", __LINE__, $hack_mouse_file) . q{ require XSLoader; XSLoader::load('Mouse', $VERSION); }; - warn $@ if $@; # for DEBUGGING + #warn $@ if $@; } if($need_pp){ @@ -24,8 +29,8 @@ BEGIN{ } -use Carp qw(confess); -use Scalar::Util qw(blessed); +use Carp (); +use Scalar::Util (); use constant _MOUSE_VERBOSE => !!$ENV{MOUSE_VERBOSE}; @@ -68,8 +73,14 @@ BEGIN { *get_metaclass_by_name = \&Mouse::Meta::Module::get_metaclass_by_name; *get_all_metaclass_instances = \&Mouse::Meta::Module::get_all_metaclass_instances; *get_all_metaclass_names = \&Mouse::Meta::Module::get_all_metaclass_names; + + # is-a predicates + generate_isa_predicate_for('Mouse::Meta::TypeConstraint' => 'is_a_type_constraint'); + generate_isa_predicate_for('Mouse::Meta::Class' => 'is_a_metaclass'); + generate_isa_predicate_for('Mouse::Meta::Role' => 'is_a_metarole'); } + # Moose::Util compatible utilities sub find_meta{ @@ -193,7 +204,7 @@ sub load_first_existing_class { } # not found - confess join( + Carp::confess join( "\n", map { sprintf( "Could not load class (%s) because : %s", @@ -209,7 +220,7 @@ sub _try_load_one_class { unless ( is_valid_class_name($class) ) { my $display = defined($class) ? $class : 'undef'; - confess "Invalid class name ($display)"; + Carp::confess "Invalid class name ($display)"; } return undef if $is_class_loaded_cache{$class} ||= is_class_loaded($class); @@ -228,7 +239,7 @@ sub _try_load_one_class { sub load_class { my $class = shift; my $e = _try_load_one_class($class); - confess "Could not load class ($class) because : $e" if $e; + Carp::confess "Could not load class ($class) because : $e" if $e; return 1; } @@ -237,7 +248,9 @@ sub is_class_loaded; sub apply_all_roles { - my $applicant = blessed($_[0]) ? shift : Mouse::Meta::Class->initialize(shift); + my $applicant = Scalar::Util::blessed($_[0]) + ? shift # instance + : Mouse::Meta::Class->initialize(shift); # class or role name my @roles; @@ -252,7 +265,7 @@ sub apply_all_roles { my $role_name = $roles[-1][0]; load_class($role_name); - Mouse::Util::TypeConstraints::_is_a_metarole( get_metaclass_by_name($role_name) ) + is_a_metarole( get_metaclass_by_name($role_name) ) || $applicant->meta->throw_error("You can only consume roles, $role_name(".$role_name->meta.") is not a Mouse role"); } @@ -321,7 +334,7 @@ Mouse::Util - Features, with or without their dependencies =head1 VERSION -This document describes Mouse version 0.40_01 +This document describes Mouse version 0.40_04 =head1 IMPLEMENTATIONS FOR