| 1 | package Class::MOP::Method; | ||||||||||||||||||||||||||||||||
| 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 Scalar::Util 'weaken', 'reftype', 'blessed'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 459 | ▶ | use parent 'Class::MOP::Object'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | # NOTE: | ||||||||||||||||||||||||||||||||
| 12 | # if poked in the right way, | ||||||||||||||||||||||||||||||||
| 13 | # they should act like CODE refs. | ||||||||||||||||||||||||||||||||
| 14 | use overload | ||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | '&{}' => sub { $_[0]->body }, | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 87787 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 166 | ▶ | '""' => sub { overload::StrVal($_[0]) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 459 | fallback => 1; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | # construction | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 92929 | ▶ | sub wrap { | ||||||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 23 | 92929 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 92929 | ▶ | unshift @args, 'body' if @args % 2 == 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 92929 | my %params = @args; | |||||||||||||||||||||||||||||||
| 28 | 92929 | my $code = $params{body}; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 92929 | ▶ | if (blessed($code) && $code->isa(__PACKAGE__)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
builtin::blessed($code) and $code->isa(__PACKAGE__)
MC/DC100%2/2
builtin::blessed($code) and $code->isa(__PACKAGE__)
builtin::blessed($code)
$code->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= builtin::blessed($code)B= $code->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||
| 31 | 2 | my $method = $code->clone; | |||||||||||||||||||||||||||||||
| 32 | 2 | delete $params{body}; | |||||||||||||||||||||||||||||||
| 33 | 2 | Class::MOP::class_of($class)->rebless_instance($method, %params); | |||||||||||||||||||||||||||||||
| 34 | 2 | return $method; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | ▶ | elsif (!ref $code || 'CODE' ne reftype($code)) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
not ref $code or "CODE" ne builtin::reftype($code)
MC/DC100%2/2
not ref $code or "CODE" ne builtin::reftype($code)
not ref $code
"CODE" ne builtin::reftype($code)
Truth table100%3/3
not(A) or B
A= not ref $codeB= "CODE" ne builtin::reftype($code)
| |||||||||||||||||||||||||||||||||
| 37 | 7 | $class->_throw_exception( WrapTakesACodeRefToBless => params => \%params, | |||||||||||||||||||||||||||||||
| 38 | class => $class, | ||||||||||||||||||||||||||||||||
| 39 | code => $code | ||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | ($params{package_name} && $params{name}) | ||||||||||||||||||||||||||||||||
| 44 | 92920 | ▶ | || $class->_throw_exception( PackageNameAndNameParamsNotGivenToWrap => params => \%params, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$params{"package_name"} and $params{"name"}
MC/DC100%2/2
$params{"package_name"} and $params{"name"}
$params{"package_name"}
$params{"name"}
Truth table100%3/3
A and B
A= $params{"package_name"}B= $params{"name"}
| |||||||||||||||||||||||||||||||||
| 45 | class => $class, | ||||||||||||||||||||||||||||||||
| 46 | code => $code | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 92916 | my $self = $class->_new(\%params); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 92916 | ▶ | weaken($self->{associated_metaclass}) if $self->{associated_metaclass}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 92916 | return $self; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 36343 | ▶ | sub _new { | ||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 57 | 36343 | my $class = shift; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 36343 | ▶ | return Class::MOP::Class->initialize($class)->new_object(@_) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | if $class ne __PACKAGE__; | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 26650 | ▶ | my $params = @_ == 1 ? $_[0] : {@_}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | return bless { | ||||||||||||||||||||||||||||||||
| 65 | 'body' => $params->{body}, | ||||||||||||||||||||||||||||||||
| 66 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||||||||||||||||||||||||||||||
| 67 | 'package_name' => $params->{package_name}, | ||||||||||||||||||||||||||||||||
| 68 | 'name' => $params->{name}, | ||||||||||||||||||||||||||||||||
| 69 | 'original_method' => $params->{original_method}, | ||||||||||||||||||||||||||||||||
| 70 | 26650 | } => $class; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | ## accessors | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 5447 | ▶ | sub associated_metaclass { shift->{'associated_metaclass'} } | ||||||||||||||||||||||||||||||
|
Subroutine
associated_metaclass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 173409 | ▶ | sub attach_to_class { | ||||||||||||||||||||||||||||||
|
Subroutine
attach_to_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 78 | 173409 | my ( $self, $class ) = @_; | |||||||||||||||||||||||||||||||
| 79 | 173409 | $self->{associated_metaclass} = $class; | |||||||||||||||||||||||||||||||
| 80 | 173409 | weaken($self->{associated_metaclass}); | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 82 | ▶ | sub detach_from_class { | ||||||||||||||||||||||||||||||
|
Subroutine
detach_from_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 84 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||
| 85 | 82 | delete $self->{associated_metaclass}; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 29 | ▶ | sub fully_qualified_name { | ||||||||||||||||||||||||||||||
|
Subroutine
fully_qualified_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 89 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 90 | 29 | $self->package_name . '::' . $self->name; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 85 | ▶ | sub original_method { (shift)->{'original_method'} } | ||||||||||||||||||||||||||||||
|
Subroutine
original_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 24761 | ▶ | sub _set_original_method { $_[0]->{'original_method'} = $_[1] } | ||||||||||||||||||||||||||||||
|
Subroutine
_set_original_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # It's possible that this could cause a loop if there is a circular | ||||||||||||||||||||||||||||||||
| 98 | # reference in here. That shouldn't ever happen in normal | ||||||||||||||||||||||||||||||||
| 99 | # circumstances, since original method only gets set when clone is | ||||||||||||||||||||||||||||||||
| 100 | # called. We _could_ check for such a loop, but it'd involve some sort | ||||||||||||||||||||||||||||||||
| 101 | # of package-lexical variable, and wouldn't be terribly subclassable. | ||||||||||||||||||||||||||||||||
| 102 | 30 | ▶ | sub original_package_name { | ||||||||||||||||||||||||||||||
|
Subroutine
original_package_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 103 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 30 | ▶ | $self->original_method | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | ? $self->original_method->original_package_name | ||||||||||||||||||||||||||||||||
| 107 | : $self->package_name; | ||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub original_name { | ||||||||||||||||||||||||||||||
|
Subroutine
original_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | $self->original_method | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | ? $self->original_method->original_name | ||||||||||||||||||||||||||||||||
| 115 | : $self->name; | ||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 13 | ▶ | sub original_fully_qualified_name { | ||||||||||||||||||||||||||||||
|
Subroutine
original_fully_qualified_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 119 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 13 | ▶ | $self->original_method | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | ? $self->original_method->original_fully_qualified_name | ||||||||||||||||||||||||||||||||
| 123 | : $self->fully_qualified_name; | ||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 42 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 127 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||
| 128 | 42 | $self->body->(@_); | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | # We used to go through use Class::MOP::Class->clone_instance to do this, but | ||||||||||||||||||||||||||||||||
| 132 | # this was awfully slow. This method may be called a number of times when | ||||||||||||||||||||||||||||||||
| 133 | # classes are loaded (especially during Moose role application), so it is | ||||||||||||||||||||||||||||||||
| 134 | # worth optimizing. - DR | ||||||||||||||||||||||||||||||||
| 135 | 24761 | ▶ | sub clone { | ||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 136 | 24761 | my $self = shift; | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 24761 | my $clone = bless { %{$self}, @_ }, blessed($self); | |||||||||||||||||||||||||||||||
| 139 | 24761 | ▶ | weaken($clone->{associated_metaclass}) if $clone->{associated_metaclass}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 24761 | $clone->_set_original_method($self); | |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 24761 | return $clone; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 26490 | ▶ | sub _inline_throw_exception { | ||||||||||||||||||||||||||||||
|
Subroutine
_inline_throw_exception: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||
| 147 | 26490 | my ( $self, $exception_type, $throw_args ) = @_; | |||||||||||||||||||||||||||||||
| 148 | return | ||||||||||||||||||||||||||||||||
| 149 | 26490 | ▶ | 'die Module::Runtime::use_module("Moose::Exception::' | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$throw_args || ''
MC/DC0%0/1
$throw_args || ''
$throw_args
Truth table50%1/2
A
A= $throw_args
| |||||||||||||||||||||||||||||||||
| 150 | . $exception_type | ||||||||||||||||||||||||||||||||
| 151 | . '")->new(' | ||||||||||||||||||||||||||||||||
| 152 | . ( $throw_args || '' ) . ')'; | ||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 459 | 1; | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | # ABSTRACT: Method Meta Object | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||||||||||||||