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.2203';
3              
4 4     4   2795 use Moose;
  4         11  
  4         27  
5             extends 'Moose::Exception';
6             with 'Moose::Exception::Role::Class';
7              
8 4     4   30 use Moose::Util 'find_meta';
  4         9  
  4         31  
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   17 my $self = shift;
18 10         251 my $class_name = $self->class_name;
19 10         298 my $superclass_name = $self->superclass_name;
20 10         279 my $metaclass_type = $self->metaclass_type;
21              
22 10         19 my $metaclass_type_name = $metaclass_type;
23 10         56 $metaclass_type_name =~ s/_(?:meta)?class$//;
24 10         23 $metaclass_type_name =~ s/_/ /g;
25              
26 10         35 my $class = find_meta( $class_name );
27              
28 10         103 my $self_metaclass_type = $class->$metaclass_type;
29              
30 8         28 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
31 8         24 my $super_metatype = $super_meta->$metaclass_type;
32              
33 8         196 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;