use Carp ();
use Scalar::Util qw(weaken);
-use Mouse::Util;
+use Mouse::Util qw(:meta);
use Mouse::Meta::TypeConstraint;
use Mouse::Meta::Method::Accessor;
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} }
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;
}
-sub meta{ Mouse::Meta::Class->initialize(ref $_[0] || $_[0]) }
-
sub _new{ Carp::croak("Mouse::Meta::Module is an abstract class") }
sub name { $_[0]->{package} }
use strict;
use warnings;
-use Mouse::Util;
+use Mouse::Util qw(does dump);
sub new {
my $class = shift;
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__
get_code_info
not_supported
+
+ does meta dump
);
our %EXPORT_TAGS = (
all => \@EXPORT_OK,
+ meta => [qw(does meta dump)],
);
# Moose::Util compatible utilities
}
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);
}
my @classes = @_
or return;
- my $found;
my %exceptions;
for my $class (@classes) {
my $e = _try_load_one_class($class);
$exceptions{$class} = $e;
}
else {
- $found = $class;
- last;
+ return $class;
}
}
- return $found if $found;
+ # not found
confess join(
"\n",
map {
return join q{, }, @items, "and $tail";
}
+
+# common utilities
+
sub not_supported{
my($feature) = @_;
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__