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.2205';
3              
4 4     4   3488 use Moose;
  4         80  
  4         96  
5             extends 'Moose::Exception';
6             with 'Moose::Exception::Role::Class';
7              
8 4     4   39 use Moose::Util 'find_meta';
  4         10  
  4         34  
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         318 my $class_name = $self->class_name;
19 10         329 my $superclass_name = $self->superclass_name;
20 10         356 my $metaclass_type = $self->metaclass_type;
21              
22 10         24 my $metaclass_type_name = $metaclass_type;
23 10         59 $metaclass_type_name =~ s/_(?:meta)?class$//;
24 10         26 $metaclass_type_name =~ s/_/ /g;
25              
26 10         36 my $class = find_meta( $class_name );
27              
28 10         135 my $self_metaclass_type = $class->$metaclass_type;
29              
30 8         29 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
31 8         23 my $super_metatype = $super_meta->$metaclass_type;
32              
33 8         256 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;