| 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
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 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(@_)
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(@_)
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 509 | ▶ | if ($meta_name->isa($other_name)) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||