MOP/Slot.pm

filter: Statementstmt 100% 44 / 44 Branchbran 92.8% 13 / 14 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 94.4% 85 / 90 CC 12 SCAR 14.0
CC
12
Cov
96%
BUILDARGS
8.0
was_aliased_from
4.0
initializer
2.0
CRAP 4.1
« MOP/Role.pm ↑ Summary MOP/Method.pm »
1 package MOP::Slot;
2 # ABSTRACT: A representation of a class slot
3  
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use UNIVERSAL::Object::Immutable;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 30 ▶use MOP::Internal::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 30 our $VERSION = '0.11';
14 30 our $AUTHORITY = 'cpan:STEVAN';
15  
16 30 ▶our @ISA; BEGIN { @ISA = 'UNIVERSAL::Object::Immutable' }
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 sub BUILDARGS {
19 60 ▶ my $class = shift;
Subroutine BUILDARGS: called CC=8 SCAR=20.8
Pod documented
20 60 my $args;
21  
22 60 ▶ if ( scalar( @_ ) eq 2 && !(ref $_[0]) && ref $_[1] eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ eq 2 and not ref $_[0] and ref $_[1] eq 'CODE') { } 1 59 60
Condition66%4/6
scalar @_ eq 2 and not ref $_[0] and ref $_[1] eq "CODE"
!ll&&!rl&&r
5901
scalar @_ eq 2 and not ref $_[0]
!ll&&!rl&&r
5901
MC/DC33%1/3
scalar @_ eq 2 and not ref $_[0] and ref $_[1] eq "CODE"
scalar @_ eq 2 not ref $_[0] ref $_[1] eq "CODE"
Truth table50%2/4
A and not(B) and C
A= scalar @_ eq 2B= not ref $_[0]C= ref $_[1] eq "CODE"
ABCresult
0XX0
10X0
1100
1111
23 1 $args = +{ name => $_[0], initializer => $_[1] };
24 }
25 else {
26 59 $args = $class->SUPER::BUILDARGS( @_ );
27 }
28  
29 Carp::croak('[ARGS] You must specify a slot name')
30 60 ▶ unless $args->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"name"} 1 59 60
31 Carp::croak('[ARGS] You must specify a slot initializer')
32 59 ▶ unless $args->{initializer};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"initializer"} 1 58 59
33 Carp::croak('[ARGS] The initializer specified must be a CODE reference')
34 unless ref $args->{initializer} eq 'CODE'
35 58 ▶ || MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $args->{initializer} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args->{"initializer"} eq "CODE" or MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"}) 1 57 58
Condition100%3/3
ref $args->{"initializer"} eq "CODE" or MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"})
l!l&&r!l&&!r
5161
MC/DC100%2/2
ref $args->{"initializer"} eq "CODE" or MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"})
ref $args->{"initializer"} eq "CODE" MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"})
Truth table100%3/3
A or B
A= ref $args->{"initializer"} eq "CODE"B= MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"})
ABresult
1X1
011
000
36  
37 57 return $args;
38 }
39  
40 sub CREATE {
41 57 ▶ my ($class, $args) = @_;
Subroutine CREATE: called CC=1 SCAR=0.0
Pod documented
42 # NOTE:
43 # Ideally this instance would actually just be
44 # a reference to an HE (C-level hash entry struct)
45 # but that is not something that is exposed at
46 # the language level. Instead we use an ARRAY
47 # ref to both 1) save space and 2) retain an
48 # illusion of opacity regarding these instances.
49 # - SL
50 57 return +[ $args->{name}, $args->{initializer} ]
51 }
52  
53 sub name {
54 16 ▶ my ($self) = @_;
Subroutine name: called CC=1 SCAR=0.0
Pod documented
55 16 return $self->[0];
56 }
57  
58 sub initializer {
59 100 ▶ my ($self) = @_;
Subroutine initializer: called CC=2 SCAR=6.9
Pod documented
60 return MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $self->[1] )
61 100 ▶ ? \&{ $self->[1] }
Branch: 1 branch
BranchTrueFalseTotal
MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($self->[1]) ? : 18 82 100
62 : $self->[1];
63 }
64  
65 sub origin_stash {
66 81 ▶ my ($self) = @_;
Subroutine origin_stash: called CC=1 SCAR=0.0
Pod documented
67 # NOTE:
68 # for the time being we are going to stick with
69 # the COMP_STASH as the indicator for the initalizers
70 # instead of the glob ref, which might be trickier
71 # however I really don't know, so time will tell.
72 # - SL
73 81 return MOP::Internal::Util::GET_STASH_NAME( $self->initializer );
74 }
75  
76 sub was_aliased_from {
77 18 ▶ my ($self, @classnames) = @_;
Subroutine was_aliased_from: called CC=4 SCAR=13.9
Pod documented
78  
79 18 ▶ Carp::croak('[ARGS] You must specify at least one classname')
Branch: 1 branch
BranchTrueFalseTotal
if scalar @classnames == 0 0 18 18
80 if scalar( @classnames ) == 0;
81  
82 18 my $class = $self->origin_stash;
83 18 foreach my $candidate ( @classnames ) {
84 18 ▶ return 1 if $candidate eq $class;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate eq $class 15 3 18
85 }
86 3 return 0;
87 }
88  
89 30 1;
90  
91 __END__
« MOP/Role.pm ↑ Summary MOP/Method.pm »