File Coverage

blib/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm
Criterion Covered Total %
statement 12 13 92.3
branch 7 8 87.5
condition 2 3 66.6
subroutine 2 2 100.0
pod n/a
total 23 26 88.4


line stmt bran cond sub pod time code
1             package Moose::Exception::InvalidArgPassedToMooseUtilMetaRole;
2             our $VERSION = '2.2206';
3              
4 2     2   1756 use Moose;
  2         6  
  2         15  
5             extends 'Moose::Exception';
6              
7             has 'argument' => (
8             is => 'ro',
9             isa => 'Any',
10             required => 1
11             );
12              
13             sub _build_message {
14 6     6   13 my $self = shift;
15 6         15 my $error = 'When using Moose::Util::MetaRole, you must pass a Moose class name,'
16             . ' role name, metaclass object, or metarole object.';
17              
18 6         227 my $arg = $self->argument;
19 6 100       40 my $found = blessed $arg ? $arg : Class::MOP::class_of($arg);
20              
21 6         12 my $error2;
22              
23 6 100 66     47 if ( defined $found && blessed $found ) {
    50          
24 3         22 $error2 = " You passed ".$arg.", and we resolved this to a "
25             . ( blessed $found )
26             . ' object.';
27             }
28             elsif ( !defined $found ) {
29 3 100       18 $error2 = " You passed ".( defined $arg ? $arg : "undef" ).", and this did not resolve to a metaclass or metarole."
30             . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
31             }
32             else {
33 0         0 $error2 = " You passed an undef."
34             . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
35             }
36              
37 6         159 $error.$error2;
38             }
39              
40             __PACKAGE__->meta->make_immutable;
41             1;