MOP/Method.pm

filter: Statementstmt 95.0% 58 / 61 Branchbran 81.2% 13 / 16 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.1% 16 / 17 Podpod 90.0% 9 / 10 totaltotal 88.1% 97 / 110 CC 12 SCAR 12.1
CC
12
Cov
89%
BUILDARGS
7.0
has_code_attributes
6.0
was_aliased_from
4.0
CRAP 3.4
« MOP/Slot.pm ↑ Summary MOP/Method/Attribute.pm »
1 package MOP::Method;
2 # ABSTRACT: A representation of a method
3  
4 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 33 ▶use attributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 33 ▶use MOP::Method::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 33 ▶use MOP::Internal::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 33 our $VERSION = '0.14';
15 33 our $AUTHORITY = 'cpan:STEVAN';
16  
17 33 ▶use parent 'UNIVERSAL::Object::Immutable';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1037 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=7 SCAR=19.5
Pod documented
20 1037 my $class = shift;
21 1037 my %args;
22  
23 1037 ▶ if ( scalar( @_ ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 1035 1037
24 2 ▶ if ( ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) 2 0 2
25 2 ▶ if ( ref $_[0] eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'CODE') { } 1 1 2
elsif (ref $_[0] eq 'HASH') { } 1 0 1
26 1 %args = ( body => $_[0] );
27 }
28 elsif (ref $_[0] eq 'HASH') {
29 1 %args = %{ $_[0] };
30 }
31 }
32 }
33 else {
34 1035 %args = @_;
35 }
36  
37 Carp::confess('[ARGS] You must specify a method body')
38 1037 ▶ unless $args{body};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"body"} 1 1036 1037
39  
40 Carp::confess('[ARGS] The body specified must be a CODE reference')
41 1036 ▶ unless ref $args{body} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"body"} eq "CODE" 1 1035 1036
42  
43 1035 return \%args;
44 }
45  
46 1035 ▶sub CREATE {
Subroutine CREATE: called CC=1 SCAR=0.0
Pod documented
47 1035 my ($class, $args) = @_;
48  
49 1035 my $body = $args->{body};
50 # this will get blessed, so we
51 # do not actually want the CV
52 # to get touched, so we get a
53 # ref of a ref here ...
54 1035 return \$body;
55 }
56  
57 546 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
58 546 my ($self) = @_;
59 546 return MOP::Internal::Util::GET_GLOB_NAME( $self->body )
60 }
61  
62 5 ▶sub fully_qualified_name {
Subroutine fully_qualified_name: called CC=1 SCAR=0.0
Pod undocumented
63 5 my ($self) = @_;
64 5 join '::' => $self->origin_stash, $self->name;
65 }
66  
67 2549 ▶sub body {
Subroutine body: called CC=1 SCAR=0.0
Pod documented
68 2549 my ($self) = @_;
69 2549 return $$self;
70 }
71  
72 929 ▶sub is_required {
Subroutine is_required: called CC=1 SCAR=0.0
Pod documented
73 929 my ($self) = @_;
74 929 MOP::Internal::Util::IS_CV_NULL( $self->body );
75 }
76  
77 611 ▶sub origin_stash {
Subroutine origin_stash: called CC=1 SCAR=0.0
Pod documented
78 611 my ($self) = @_;
79 # NOTE:
80 # Here we actually want the stash that is
81 # associated with the GV (glob) that the
82 # method body is associated with. This is
83 # sometimes different then the COMP_STASH
84 # meaning the stash it was compiled in. It
85 # seems to vary most with required subs,
86 # which seem to be compiled in main:: even
87 # when I am expecting it not to be.
88 # - SL
89 611 return MOP::Internal::Util::GET_GLOB_STASH_NAME( $self->body )
90 }
91  
92 25 ▶sub was_aliased_from {
Subroutine was_aliased_from: called CC=4 SCAR=13.9
Pod documented
93 25 my ($self, @classnames) = @_;
94  
95 25 ▶ Carp::confess('[ARGS] You must specify at least one classname')
Branch: 1 branch
BranchTrueFalseTotal
if scalar @classnames == 0 0 25 25
96 if scalar( @classnames ) == 0;
97  
98 25 my $class = $self->origin_stash;
99 25 foreach my $candidate ( @classnames ) {
100 25 ▶ return 1 if $candidate eq $class;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate eq $class 18 7 25
101 }
102 7 return 0;
103 }
104  
105 0 ▶sub has_code_attributes {
Subroutine has_code_attributes: not called CC=2 SCAR=17.9
Pod documented
106 0 my ($self, $to_match) = @_;
107 0 ▶ $to_match //= '.';
Condition0%0/2
$to_match //= "."
l!l
00
MC/DC0%0/1
$to_match //= "."
$to_match
Truth table0%0/2
A
A= $to_match
Aresult
11
00
108 0 return scalar grep /^$to_match/, attributes::get( $self->body );
109 }
110  
111 2 ▶sub get_code_attributes {
Subroutine get_code_attributes: called CC=2 SCAR=7.1
Pod documented
112 2 my ($self, $to_match) = @_;
113 2 ▶ $to_match //= '.';
Condition50%1/2
$to_match //= "."
l!l
20
MC/DC0%0/1
$to_match //= "."
$to_match
Truth table50%1/2
A
A= $to_match
Aresult
11
00
114 2 return map MOP::Method::Attribute->new( $_ ), grep /^$to_match/, attributes::get( $self->body );
115 }
116  
117 33 1;
118  
119 __END__
« MOP/Slot.pm ↑ Summary MOP/Method/Attribute.pm »