blib/lib/Class/MOP/Method.pm

filter: Statementstmt 100% 64 / 64 Branchbran 95.4% 21 / 22 Conditioncond 90.9% 10 / 11 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 22 / 22 Podpod 100% 9 / 9 totaltotal 97.7% 132 / 135 CC 16 SCAR 12.2
CC
16
Cov
98%
wrap
9.0
_new
3.0
_inline_throw_exception
2.1
CRAP 3.4
« blib/lib/Class/MOP/Package.pm ↑ Summary blib/lib/Moose/Meta/Class/Immutable/Trait.pm »
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
BranchTrueFalseTotal
if @args % 2 == 1 49064 43865 92929
26  
27 92929 my %params = @args;
28 92929 my $code = $params{body};
29  
30 92929 ▶ if (blessed($code) && $code->isa(__PACKAGE__)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($code) and $code->isa(__PACKAGE__)) { } 2 92927 92929
elsif (not ref $code or 'CODE' ne builtin::reftype($code)) { } 7 92920 92927
Condition100%3/3
builtin::blessed($code) and $code->isa(__PACKAGE__)
!ll&&!rl&&r
9292432
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__)
ABresult
0X0
100
111
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)
l!l&&r!l&&!r
4392920
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$params{"package_name"} and $params{"name"} or $class->_throw_exception("PackageNameAndNameParamsNotGivenToWrap", "params", \%params, "class", $class, "code", $code) 92916 4 92920
Condition100%3/3
$params{"package_name"} and $params{"name"}
!ll&&!rl&&r
3192916
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $self->{"associated_metaclass"} 75993 16923 92916
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
BranchTrueFalseTotal
if $class ne __PACKAGE__ 9693 26650 36343
60 if $class ne __PACKAGE__;
61  
62 26650 ▶ my $params = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 26650 0 26650
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
BranchTrueFalseTotal
$self->original_method ? : 15 15 30
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
BranchTrueFalseTotal
$self->original_method ? : 3 3 6
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
BranchTrueFalseTotal
$self->original_method ? : 7 6 13
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
BranchTrueFalseTotal
if $clone->{"associated_metaclass"} 24756 5 24761
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 || ''
l!l
264900
MC/DC0%0/1
$throw_args || ''
$throw_args
Truth table50%1/2
A
A= $throw_args
Aresult
11
00
150 . $exception_type
151 . '")->new('
152 . ( $throw_args || '' ) . ')';
153 }
154  
155 459 1;
156  
157 # ABSTRACT: Method Meta Object
158  
159 __END__
« blib/lib/Class/MOP/Package.pm ↑ Summary blib/lib/Moose/Meta/Class/Immutable/Trait.pm »