summaryrefslogtreecommitdiff
path: root/lib/Moose/Exception/InvalidArgPassedToMooseUtilMetaRole.pm
blob: 2910e7a02b2798289999fea44b0fdb4f67a58983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Moose::Exception::InvalidArgPassedToMooseUtilMetaRole;
our $VERSION = '2.1405';

use Moose;
extends 'Moose::Exception';

has 'argument' => (
    is       => 'ro',
    isa      => 'Any',
    required => 1
);

sub _build_message {
    my $self = shift;
    my $error = 'When using Moose::Util::MetaRole, you must pass a Moose class name,'
        . ' role name, metaclass object, or metarole object.';

    my $arg = $self->argument;
    my $found = blessed $arg ? $arg : Class::MOP::class_of($arg);

    my $error2;

    if ( defined $found && blessed $found ) {
        $error2 = " You passed ".$arg.", and we resolved this to a "
            . ( blessed $found )
            . ' object.';
    }
    elsif ( !defined $found ) {
        $error2 = " You passed ".( defined $arg ? $arg : "undef" ).", and this did not resolve to a metaclass or metarole."
            . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
    }
    else {
        $error2 = " You passed an undef."
            . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
    }

    $error.$error2;
}

1;