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