X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FPurePerl.pm;h=fc6b45786a4c6248e421b65c4286a98eabd630c3;hb=5d3ab42b8c257acdf05ce9ac602ec16a5923a879;hp=17017ddb64fc2beff3bbb2f4943ccd904b28de1e;hpb=8aba926dbf11e9cf418c7c79b925d15e60e1e990;p=gitmo%2FMouse.git diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index 17017dd..fc6b457 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -18,15 +18,20 @@ sub is_class_loaded { return 0 if ref($class) || !defined($class) || !length($class); # walk the symbol table tree to avoid autovififying - # \*{${main::}{"Foo::"}} == \*main::Foo:: + # \*{${main::}{"Foo::"}{"Bar::"}} == \*main::Foo::Bar:: my $pack = \%::; foreach my $part (split('::', $class)) { - my $entry = \$pack->{$part . '::'}; + $part .= '::'; + return 0 if !exists $pack->{$part}; + + my $entry = \$pack->{$part}; return 0 if ref($entry) ne 'GLOB'; - $pack = *{$entry}{HASH} or return 0; + $pack = *{$entry}{HASH}; } + return 0 if !%{$pack}; + # check for $VERSION or @ISA return 1 if exists $pack->{VERSION} && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} }; @@ -92,6 +97,32 @@ sub generate_isa_predicate_for { return $predicate; } +sub generate_can_predicate_for { + my($methods_ref, $name) = @_; + + my @methods = @{$methods_ref}; + + my $predicate = sub{ + my($instance) = @_; + if(Scalar::Util::blessed($instance)){ + foreach my $method(@methods){ + if(!$instance->can($method)){ + return 0; + } + } + return 1; + } + return 0; + }; + + if(defined $name){ + no strict 'refs'; + *{ caller() . '::' . $name } = $predicate; + return; + } + + return $predicate; +} package Mouse::Util::TypeConstraints; @@ -199,7 +230,6 @@ sub add_method { return; } - package Mouse::Meta::Class; @@ -492,7 +522,7 @@ Mouse::PurePerl - A Mouse guts in pure Perl =head1 VERSION -This document describes Mouse version 0.40_07 +This document describes Mouse version 0.43 =head1 SEE ALSO