line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MOP::Slot; |
2
|
|
|
|
|
|
|
# ABSTRACT: A representation of a class slot |
3
|
|
|
|
|
|
|
|
4
|
30
|
|
|
30
|
|
132426
|
use strict; |
|
30
|
|
|
|
|
91
|
|
|
30
|
|
|
|
|
944
|
|
5
|
30
|
|
|
30
|
|
174
|
use warnings; |
|
30
|
|
|
|
|
64
|
|
|
30
|
|
|
|
|
873
|
|
6
|
|
|
|
|
|
|
|
7
|
30
|
|
|
30
|
|
176
|
use Carp (); |
|
30
|
|
|
|
|
75
|
|
|
30
|
|
|
|
|
634
|
|
8
|
|
|
|
|
|
|
|
9
|
30
|
|
|
30
|
|
920
|
use UNIVERSAL::Object::Immutable; |
|
30
|
|
|
|
|
3766
|
|
|
30
|
|
|
|
|
795
|
|
10
|
|
|
|
|
|
|
|
11
|
30
|
|
|
30
|
|
848
|
use MOP::Internal::Util; |
|
30
|
|
|
|
|
79
|
|
|
30
|
|
|
|
|
2035
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
14
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
15
|
|
|
|
|
|
|
|
16
|
30
|
|
|
30
|
|
12935
|
our @ISA; BEGIN { @ISA = 'UNIVERSAL::Object::Immutable' } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub BUILDARGS { |
19
|
60
|
|
|
60
|
1
|
15077
|
my $class = shift; |
20
|
60
|
|
|
|
|
87
|
my $args; |
21
|
|
|
|
|
|
|
|
22
|
60
|
100
|
66
|
|
|
264
|
if ( scalar( @_ ) eq 2 && !(ref $_[0]) && ref $_[1] eq 'CODE' ) { |
|
|
|
66
|
|
|
|
|
23
|
1
|
|
|
|
|
6
|
$args = +{ name => $_[0], initializer => $_[1] }; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
59
|
|
|
|
|
197
|
$args = $class->SUPER::BUILDARGS( @_ ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Carp::confess('[ARGS] You must specify a slot name') |
30
|
60
|
100
|
|
|
|
906
|
unless $args->{name}; |
31
|
|
|
|
|
|
|
Carp::confess('[ARGS] You must specify a slot initializer') |
32
|
59
|
100
|
|
|
|
309
|
unless $args->{initializer}; |
33
|
|
|
|
|
|
|
Carp::confess('[ARGS] The initializer specified must be a CODE reference') |
34
|
|
|
|
|
|
|
unless ref $args->{initializer} eq 'CODE' |
35
|
58
|
100
|
100
|
|
|
193
|
|| MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $args->{initializer} ); |
36
|
|
|
|
|
|
|
|
37
|
57
|
|
|
|
|
116
|
return $args; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub CREATE { |
41
|
57
|
|
|
57
|
1
|
584
|
my ($class, $args) = @_; |
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
|
|
|
|
|
179
|
return +[ $args->{name}, $args->{initializer} ] |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub name { |
54
|
16
|
|
|
16
|
1
|
9685
|
my ($self) = @_; |
55
|
16
|
|
|
|
|
74
|
return $self->[0]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub initializer { |
59
|
100
|
|
|
100
|
1
|
2931
|
my ($self) = @_; |
60
|
|
|
|
|
|
|
return MOP::Internal::Util::CAN_COERCE_TO_CODE_REF( $self->[1] ) |
61
|
100
|
100
|
|
|
|
271
|
? \&{ $self->[1] } |
|
18
|
|
|
|
|
59
|
|
62
|
|
|
|
|
|
|
: $self->[1]; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub origin_stash { |
66
|
81
|
|
|
81
|
1
|
612
|
my ($self) = @_; |
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
|
|
|
|
|
164
|
return MOP::Internal::Util::GET_STASH_NAME( $self->initializer ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub was_aliased_from { |
77
|
18
|
|
|
18
|
1
|
78
|
my ($self, @classnames) = @_; |
78
|
|
|
|
|
|
|
|
79
|
18
|
50
|
|
|
|
61
|
Carp::confess('[ARGS] You must specify at least one classname') |
80
|
|
|
|
|
|
|
if scalar( @classnames ) == 0; |
81
|
|
|
|
|
|
|
|
82
|
18
|
|
|
|
|
47
|
my $class = $self->origin_stash; |
83
|
18
|
|
|
|
|
47
|
foreach my $candidate ( @classnames ) { |
84
|
18
|
100
|
|
|
|
113
|
return 1 if $candidate eq $class; |
85
|
|
|
|
|
|
|
} |
86
|
3
|
|
|
|
|
19
|
return 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |