blib/lib/Class/MOP/Object.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 100% 10 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 93.3% 14 / 15 Podpod 100% 2 / 2 totaltotal 90.4% 76 / 84 CC 8 SCAR 8.6
CC
8
Cov
91%
dump
6.0
_get_compatible_metaclass_by_subclassing
4.0
_make_compatible_with
3.0
CRAP 2.4
« blib/lib/Moose/Meta/Method/Accessor/Native.pm ↑ Summary blib/lib/Moose/Meta/Object/Trait.pm »
1 package Class::MOP::Object;
2 460 our $VERSION = '2.4001';
3  
4 460 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 460 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 460 ▶use parent 'Class::MOP::Mixin';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 460 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 460 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # introspection
12  
13 3 ▶sub throw_error {
Subroutine throw_error: called CC=1 SCAR=0.0
Pod documented
14 3 shift->_throw_exception( Legacy => message => join('', @_) );
15 }
16  
17 1 ▶sub _inline_throw_error {
Subroutine _inline_throw_error: called CC=1 SCAR=0.0
18 1 my ( $self, $message ) = @_;
19 1 return 'die Module::Runtime::use_module("Moose::Exception::Legacy")->new(message => ' . $message. ')';
20 }
21  
22 398 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
23 398 Class::MOP::class_of(shift)->new_object(@_);
24 }
25  
26 # RANT:
27 # Cmon, how many times have you written
28 # the following code while debugging:
29 #
30 # use Data::Dumper;
31 # warn Dumper $obj;
32 #
33 # It can get seriously annoying, so why
34 # not just do this ...
35 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod documented
36 0 my $self = shift;
37 0 require Data::Dumper;
38 0 ▶ local $Data::Dumper::Maxdepth = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
39 0 Data::Dumper::Dumper $self;
40 }
41  
42 197 ▶sub _real_ref_name {
Subroutine _real_ref_name: called CC=1 SCAR=0.0
43 197 my $self = shift;
44 197 return blessed($self);
45 }
46  
47 163290 ▶sub _is_compatible_with {
Subroutine _is_compatible_with: called CC=1 SCAR=0.0
48 163290 my $self = shift;
49 163290 my ($other_name) = @_;
50  
51 163290 return $self->isa($other_name);
52 }
53  
54 140457 ▶sub _can_be_made_compatible_with {
Subroutine _can_be_made_compatible_with: called CC=2 SCAR=6.9
55 140457 my $self = shift;
56 140457 ▶ return !$self->_is_compatible_with(@_)
Condition100%3/3
!$self->_is_compatible_with(@_) && defined $self->_get_compatible_metaclass(@_)
!ll&&!rl&&r
14017735245
MC/DC100%2/2
!$self->_is_compatible_with(@_) && defined $self->_get_compatible_metaclass(@_)
!$self->_is_compatible_with(@_) defined $self->_get_compatible_metaclass(@_)
Truth table100%3/3
not(A) && B
A= !$self->_is_compatible_with(@_)B= defined $self->_get_compatible_metaclass(@_)
ABresult
0X0
100
111
57 && defined($self->_get_compatible_metaclass(@_));
58 }
59  
60 115 ▶sub _make_compatible_with {
Subroutine _make_compatible_with: called CC=3 SCAR=11.0
61 115 my $self = shift;
62 115 my ($other_name) = @_;
63  
64 115 my $new_metaclass = $self->_get_compatible_metaclass($other_name);
65  
66 115 ▶ unless ( defined $new_metaclass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_metaclass) 3 112 115
67 3 $self->_throw_exception( CannotMakeMetaclassCompatible => superclass_name => $other_name,
68 class => $self,
69 );
70 }
71  
72 # can't use rebless_instance here, because it might not be an actual
73 # subclass in the case of, e.g. moose role reconciliation
74 112 ▶ $new_metaclass->meta->_force_rebless_instance($self)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($self) ne $new_metaclass 78 34 112
75 if blessed($self) ne $new_metaclass;
76  
77 112 return $self;
78 }
79  
80 509 ▶sub _get_compatible_metaclass {
Subroutine _get_compatible_metaclass: called CC=1 SCAR=0.0
81 509 my $self = shift;
82 509 my ($other_name) = @_;
83  
84 509 return $self->_get_compatible_metaclass_by_subclassing($other_name);
85 }
86  
87 509 ▶sub _get_compatible_metaclass_by_subclassing {
Subroutine _get_compatible_metaclass_by_subclassing: called CC=4 SCAR=13.9
88 509 my $self = shift;
89 509 my ($other_name) = @_;
90 509 ▶ my $meta_name = blessed($self) ? $self->_real_ref_name : $self;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 254 255 509
91  
92 509 ▶ if ($meta_name->isa($other_name)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($meta_name->isa($other_name)) { } 34 475 509
elsif ($other_name->isa($meta_name)) { } 392 83 475
93 34 return $meta_name;
94 }
95 elsif ($other_name->isa($meta_name)) {
96 392 return $other_name;
97 }
98  
99 83 return;
100 }
101  
102 460 1;
103  
104 # ABSTRACT: Base class for metaclasses
105  
106 __END__
« blib/lib/Moose/Meta/Method/Accessor/Native.pm ↑ Summary blib/lib/Moose/Meta/Object/Trait.pm »