| 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 MOP::Internal::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 30 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 30 | our $AUTHORITY = 'cpan:STEVAN'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 30 | ▶ | use parent 'UNIVERSAL::Object::Immutable'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 72 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 72 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 72 | my $args; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 72 | ▶ | if ( scalar( @_ ) eq 2 && !(ref $_[0]) && ref $_[1] eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
scalar @_ eq 2 and not ref $_[0] and ref $_[1] eq "CODE"
scalar @_ eq 2 and not ref $_[0]
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | $args = +{ name => $_[0], initializer => $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 71 | $args = $class->SUPER::BUILDARGS( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | Carp::confess('[ARGS] You must specify a slot name') | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 72 | ▶ | unless $args->{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | Carp::confess('[ARGS] You must specify a slot initializer') | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 71 | ▶ | unless $args->{initializer}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | Carp::confess('[ARGS] The initializer specified must be a CODE reference') | ||||||||||||||||||||||||||||||||||||||||||
| 32 | unless ref $args->{initializer} eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 70 | ▶ | || MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $args->{initializer} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $args->{"initializer"} eq "CODE" or MOP::Internal::Util::CAN_COERCE_TO_CODE_REF($args->{"initializer"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 69 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 69 | ▶ | sub CREATE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CREATE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 69 | my ($class, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | # NOTE: | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # Ideally this instance would actually just be | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # a reference to an HE (C-level hash entry struct) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # but that is not something that is exposed at | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # the language level. Instead we use an ARRAY | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # ref to both 1) save space and 2) retain an | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # illusion of opacity regarding these instances. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # - SL | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 69 | return +[ $args->{name}, $args->{initializer} ] | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | return $self->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 110 | ▶ | sub initializer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initializer: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 110 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | return MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $self->[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 110 | ▶ | ? \&{ $self->[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | : $self->[1]; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 91 | ▶ | sub origin_stash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
origin_stash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 91 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | # NOTE: | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # for the time being we are going to stick with | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # the COMP_STASH as the indicator for the initalizers | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # instead of the glob ref, which might be trickier | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # however I really don't know, so time will tell. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # - SL | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 91 | return MOP::Internal::Util::GET_STASH_NAME( $self->initializer ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 18 | ▶ | sub was_aliased_from { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
was_aliased_from: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 18 | my ($self, @classnames) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 18 | ▶ | Carp::confess('[ARGS] You must specify at least one classname') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | if scalar( @classnames ) == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 18 | my $class = $self->origin_stash; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | foreach my $candidate ( @classnames ) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 18 | ▶ | return 1 if $candidate eq $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||||||||||||||||