File Coverage

blib/lib/Moose/Exception/MetaclassTypeIncompatible.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Moose::Exception::MetaclassTypeIncompatible;
2             our $VERSION = '2.2206';
3              
4 4     4   3213 use Moose;
  4         15  
  4         27  
5             extends 'Moose::Exception';
6             with 'Moose::Exception::Role::Class';
7              
8 4     4   45 use Moose::Util 'find_meta';
  4         11  
  4         36  
9              
10             has [qw(superclass_name metaclass_type)] => (
11             is => 'ro',
12             isa => 'Str',
13             required => 1
14             );
15              
16             sub _build_message {
17 10     10   20 my $self = shift;
18 10         306 my $class_name = $self->class_name;
19 10         326 my $superclass_name = $self->superclass_name;
20 10         343 my $metaclass_type = $self->metaclass_type;
21              
22 10         20 my $metaclass_type_name = $metaclass_type;
23 10         56 $metaclass_type_name =~ s/_(?:meta)?class$//;
24 10         25 $metaclass_type_name =~ s/_/ /g;
25              
26 10         34 my $class = find_meta( $class_name );
27              
28 10         120 my $self_metaclass_type = $class->$metaclass_type;
29              
30 8         21 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
31 8         24 my $super_metatype = $super_meta->$metaclass_type;
32              
33 8         259 return "The $metaclass_type metaclass for $class_name"
34             . " ($self_metaclass_type) is not compatible with the $metaclass_type_name"
35             . " metaclass of its superclass, $superclass_name ($super_metatype)";
36             }
37              
38             __PACKAGE__->meta->make_immutable;
39             1;