| 1 | package Class::MOP::Overload; | ||||||||||||||||||||||||||||
| 2 | 459 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 459 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 459 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 459 | ▶ | use overload (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 459 | ▶ | use Scalar::Util qw( blessed weaken ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 459 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 459 | ▶ | use parent 'Class::MOP::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | my %Operators = ( | ||||||||||||||||||||||||||||
| 14 | 33966 | map { $_ => 1 } | |||||||||||||||||||||||||||
| 15 | 34425 | grep { $_ ne 'fallback' } | |||||||||||||||||||||||||||
| 16 | 459 | map { split /\s+/ } values %overload::ops | |||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 23 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 23 | my ( $class, %params ) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 23 | ▶ | unless ( defined $params{operator} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | $class->_throw_exception('OverloadRequiresAnOperator'); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 23 | ▶ | unless ( $Operators{ $params{operator} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | $class->_throw_exception( | ||||||||||||||||||||||||||||
| 27 | 'InvalidOverloadOperator', | ||||||||||||||||||||||||||||
| 28 | operator => $params{operator}, | ||||||||||||||||||||||||||||
| 29 | 0 | ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 23 | ▶ | unless ( defined $params{method_name} || $params{coderef} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params{"method_name"} or $params{"coderef"}
MC/DC0%0/2
defined $params{"method_name"} or $params{"coderef"}
defined $params{"method_name"}
$params{"coderef"}
Truth table66%2/3
A or B
A= defined $params{"method_name"}B= $params{"coderef"}
| |||||||||||||||||||||||||||||
| 33 | $class->_throw_exception( | ||||||||||||||||||||||||||||
| 34 | 'OverloadRequiresAMethodNameOrCoderef', | ||||||||||||||||||||||||||||
| 35 | operator => $params{operator}, | ||||||||||||||||||||||||||||
| 36 | 0 | ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 23 | ▶ | if ( $params{coderef} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | unless ( defined $params{coderef_package} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"coderef_package"} and defined $params{"coderef_name"}
MC/DC0%0/2
defined $params{"coderef_package"} and defined $params{"coderef_name"}
defined $params{"coderef_package"}
defined $params{"coderef_name"}
Truth table33%1/3
A and B
A= defined $params{"coderef_package"}B= defined $params{"coderef_name"}
| |||||||||||||||||||||||||||||
| 41 | && defined $params{coderef_name} ) { | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | $class->_throw_exception('OverloadRequiresNamesForCoderef'); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 23 | ▶ | if ( $params{method} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params{"method"} and not &try(sub {
$params{"method"}->isa("Class::MOP::Method");
}
)
MC/DC0%0/2
$params{"method"} and not &try(sub {
$params{"method"}->isa("Class::MOP::Method");
}
)
$params{"method"}
not &try(sub {
$params{"method"}->isa("Class::MOP::Method");
}
)
Truth table66%2/3
A and not(B)
A= $params{"method"}B= not &try(sub {
$params{"method"}->isa("Class::MOP::Method");
}
)
| |||||||||||||||||||||||||||||
| 48 | 15 | ▶ | && !try { $params{method}->isa('Class::MOP::Method') } ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $class->_throw_exception('OverloadRequiresAMetaMethod'); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 23 | ▶ | if ( $params{associated_metaclass} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params{"associated_metaclass"} and not &try(sub {
$params{"associated_metaclass"}->isa("Class::MOP::Module");
}
)
MC/DC0%0/2
$params{"associated_metaclass"} and not &try(sub {
$params{"associated_metaclass"}->isa("Class::MOP::Module");
}
)
$params{"associated_metaclass"}
not &try(sub {
$params{"associated_metaclass"}->isa("Class::MOP::Module");
}
)
Truth table66%2/3
A and not(B)
A= $params{"associated_metaclass"}B= not &try(sub {
$params{"associated_metaclass"}->isa("Class::MOP::Module");
}
)
| |||||||||||||||||||||||||||||
| 54 | 21 | ▶ | && !try { $params{associated_metaclass}->isa('Class::MOP::Module') } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $class->_throw_exception('OverloadRequiresAMetaClass'); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | my @optional_attrs | ||||||||||||||||||||||||||||
| 61 | 23 | = qw( method_name coderef coderef_package coderef_name method associated_metaclass ); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | return bless { | ||||||||||||||||||||||||||||
| 64 | operator => $params{operator}, | ||||||||||||||||||||||||||||
| 65 | 23 | ▶ | map { defined $params{$_} ? ( $_ => $params{$_} ) : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | @optional_attrs | ||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||
| 68 | $class; | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 51 | ▶ | sub operator { $_[0]->{operator} } | ||||||||||||||||||||||||||
|
Subroutine
operator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 36 | ▶ | sub method_name { $_[0]->{method_name} } | ||||||||||||||||||||||||||
|
Subroutine
method_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 3 | ▶ | sub has_method_name { exists $_[0]->{method_name} } | ||||||||||||||||||||||||||
|
Subroutine
has_method_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | sub method { $_[0]->{method} } | ||||||||||||||||||||||||||
|
Subroutine
method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 3 | ▶ | sub has_method { exists $_[0]->{method} } | ||||||||||||||||||||||||||
|
Subroutine
has_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 17 | ▶ | sub coderef { $_[0]->{coderef} } | ||||||||||||||||||||||||||
|
Subroutine
coderef: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 46 | ▶ | sub has_coderef { exists $_[0]->{coderef} } | ||||||||||||||||||||||||||
|
Subroutine
has_coderef: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub coderef_package { $_[0]->{coderef_package} } | ||||||||||||||||||||||||||
|
Subroutine
coderef_package: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub has_coderef_package { exists $_[0]->{coderef_package} } | ||||||||||||||||||||||||||
|
Subroutine
has_coderef_package: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 4 | ▶ | sub coderef_name { $_[0]->{coderef_name} } | ||||||||||||||||||||||||||
|
Subroutine
coderef_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub has_coderef_name { exists $_[0]->{coderef_name} } | ||||||||||||||||||||||||||
|
Subroutine
has_coderef_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 6 | ▶ | sub associated_metaclass { $_[0]->{associated_metaclass} } | ||||||||||||||||||||||||||
|
Subroutine
associated_metaclass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 4 | ▶ | sub is_anonymous { | ||||||||||||||||||||||||||
|
Subroutine
is_anonymous: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | 4 | ▶ | return $self->has_coderef && $self->coderef_name eq '__ANON__'; | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->has_coderef && $self->coderef_name eq '__ANON__'
MC/DC100%2/2
$self->has_coderef && $self->coderef_name eq '__ANON__'
$self->has_coderef
$self->coderef_name eq '__ANON__'
Truth table100%3/3
A && B
A= $self->has_coderefB= $self->coderef_name eq '__ANON__'
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 18 | ▶ | sub attach_to_class { | ||||||||||||||||||||||||||
|
Subroutine
attach_to_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 18 | my ( $self, $class ) = @_; | |||||||||||||||||||||||||||
| 97 | 18 | $self->{associated_metaclass} = $class; | |||||||||||||||||||||||||||
| 98 | 18 | weaken $self->{associated_metaclass}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 16 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 16 | my $clone = bless { %{$self}, @_ }, blessed($self); | |||||||||||||||||||||||||||
| 105 | 16 | ▶ | weaken $clone->{associated_metaclass} if $clone->{associated_metaclass}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 16 | $clone->_set_original_overload($self); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 16 | return $clone; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub original_overload { $_[0]->{original_overload} } | ||||||||||||||||||||||||||
|
Subroutine
original_overload: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 16 | ▶ | sub _set_original_overload { $_[0]->{original_overload} = $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
_set_original_overload: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 15 | ▶ | sub _is_equal_to { | ||||||||||||||||||||||||||
|
Subroutine
_is_equal_to: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 116 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | 15 | my $other = shift; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 15 | ▶ | if ( $self->has_coderef ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 7 | ▶ | return unless $other->has_coderef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 7 | return $self->coderef == $other->coderef; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||
| 124 | 8 | return $self->method_name eq $other->method_name; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 459 | 1; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # ABSTRACT: Overload Meta Object | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||