| 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
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | Carp::croak('[ARGS] You must specify a slot initializer') | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 59 | ▶ | unless $args->{initializer}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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"})
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||||||||||||||||