package Mouse::Util;
use Mouse::Exporter; # enables strict and warnings
+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';
+
+ my $need_pp = !!$ENV{MOUSE_PUREPERL};
+
+ if(!$need_pp && !exists $INC{'Mouse/PurePerl.pm'}){
+ local $@;
+
+ # 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 $@;
+ }
+
+ if($need_pp){
+ require 'Mouse/PurePerl.pm'; # we don't want to create its namespace
+ }
+}
+
+
use Carp qw(confess);
use Scalar::Util qw(blessed);
-use B ();
use constant _MOUSE_VERBOSE => !!$ENV{MOUSE_VERBOSE};
get_code_info
get_code_package
+ get_code_ref
not_supported
# The ':meta' group is 'use metaclass' for Mouse
meta => [qw(does meta dump _MOUSE_VERBOSE)],
},
- _export_to_main => 1,
);
# aliases as public APIs
*get_linear_isa = $impl;
}
-{ # taken from Sub::Identify
- sub get_code_info($) {
- my ($coderef) = @_;
- ref($coderef) or return;
-
- my $cv = B::svref_2object($coderef);
- $cv->isa('B::CV') or return;
-
- my $gv = $cv->GV;
- $gv->isa('B::GV') or return;
-
- return ($gv->STASH->NAME, $gv->NAME);
- }
-
- sub get_code_package{
- my($coderef) = @_;
-
- my $cv = B::svref_2object($coderef);
- $cv->isa('B::CV') or return '';
-
- my $gv = $cv->GV;
- $gv->isa('B::GV') or return '';
-
- return $gv->STASH->NAME;
- }
-}
# taken from Mouse::Util (0.90)
{
# Utilities from Class::MOP
+sub get_code_info;
+sub get_code_package;
# taken from Class/MOP.pm
sub is_valid_class_name {
return 1;
}
-
-sub is_class_loaded {
- my $class = shift;
-
- return 0 if ref($class) || !defined($class) || !length($class);
-
- # walk the symbol table tree to avoid autovififying
- # \*{${main::}{"Foo::"}} == \*main::Foo::
-
- my $pack = \%::;
- foreach my $part (split('::', $class)) {
- my $entry = \$pack->{$part . '::'};
- return 0 if ref($entry) ne 'GLOB';
- $pack = *{$entry}{HASH} or return 0;
- }
-
- # check for $VERSION or @ISA
- return 1 if exists $pack->{VERSION}
- && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
- return 1 if exists $pack->{ISA}
- && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
-
- # check for any method
- foreach my $name( keys %{$pack} ) {
- my $entry = \$pack->{$name};
- return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
- }
-
- # fail
- return 0;
-}
+sub is_class_loaded;
sub apply_all_roles {
my $role_name = $roles[-1][0];
load_class($role_name);
- my $metarole = get_metaclass_by_name($role_name);
- ( $metarole && $metarole->isa('Mouse::Meta::Role') )
+ Mouse::Util::TypeConstraints::_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");
}
=head1 VERSION
-This document describes Mouse version 0.37_06
+This document describes Mouse version 0.40_01
=head1 IMPLEMENTATIONS FOR