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.2203';
3              
4 2     2   1368 use Moose;
  2         6  
  2         13  
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   12 my $self = shift;
15 6         11 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         196 my $arg = $self->argument;
19 6 100       27 my $found = blessed $arg ? $arg : Class::MOP::class_of($arg);
20              
21 6         18 my $error2;
22              
23 6 100 66     39 if ( defined $found && blessed $found ) {
    50          
24 3         20 $error2 = " You passed ".$arg.", and we resolved this to a "
25             . ( blessed $found )
26             . ' object.';
27             }
28             elsif ( !defined $found ) {
29 3 100       14 $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         147 $error.$error2;
38             }
39              
40             __PACKAGE__->meta->make_immutable;
41             1;