TaggedAttributes/Role.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 85.7% 48 / 56 CC 5 SCAR 8.0
CC
5
Cov
91%
_tags
4.5
__ANON__
2.0
BEGIN
1.0
CRAP 2.2
« TaggedAttributes/Cache.pm ↑ Summary TaggedAttributes/Propagate.pm »
1 package MooX::TaggedAttributes::Role;
2  
3 # ABSTRACT: "Parent" Tag Role
4  
5 ## no critic
6 6 our $VERSION = '0.18';
7 ## use critic
8  
9 6 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use MooX::TaggedAttributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Sub::Name ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Moo::Role won't compose anything before it was used into a consuming
16 # package.
17 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # sub import;
20 # *import = \&MooX::TaggedAttributes::import;
21  
22 92 ▶my $maybe_next_method = sub { ( shift )->maybe::next::method };
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 # this modifier is run once for each composition of a tag role into
25 # the class. role composition is orthogonal to class inheritance, so we
26 # need to carefully handle both
27  
28 # see http://www.nntp.perl.org/group/perl.moose/2015/01/msg287{6,7,8}.html,
29 # but note that djerius' published solution was incomplete.
30 92 ▶around _tag_list => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
31  
32 # 1. call &$orig to handle tag role compositions into the current class
33 # 2. call up the inheritance stack to handle parent class tag role compositions.
34  
35 92 my $orig = shift;
36 92 my $package = caller;
37  
38 # create the proper environment context for next::can
39 92 my $code
40 = Sub::Name::subname( "${package}::_tag_list" => $maybe_next_method );
41 92 my $next = $_[0]->$code;
42  
43 # say STDERR "$package => $code";;
44  
45 92 ▶ return [ @{&$orig}, $next ? @{$next} : () ];
Branch: 1 branch
BranchTrueFalseTotal
$next ? : 24 68 92
46 6 };
47  
48  
49 # _tags can't be lazy; we must resolve the tags and attributes at
50 # object creation time in case a role is modified after this object
51 # is created, as we scan both clsses and roles to gather the tags.
52 # classes should be immutable after the first instantiation
53 # of an object (but see RT#101631), but roles aren't.
54  
55 # We also need to identify when a role has been added to an *object*
56 # which adds tagged attributes. TODO: make this work.
57  
58 # this is where all of the tags get stored while a class is being
59 # built up. eventually they are condensed into a simple hash via
60 # _build_cache
61  
62 92 ▶sub _tag_list { [] }
Subroutine _tag_list: called CC=1 SCAR=0.0
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77 68 ▶sub _tags {
Subroutine _tags: called CC=4 SCAR=15.0
78 68 my $class = Scalar::Util::blessed $_[0];
79  
80 # called as an object method?
81 68 ▶ if ( defined $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) { } 16 52 68
82 16 ▶ return $MooX::TaggedAttributes::TAGCACHE{$class}
Condition33%1/3
$MooX::TaggedAttributes::TAGCACHE{$class} //= "MooX::TaggedAttributes::Cache"->new($class)
l!l&&r!l&&!r
0160
MC/DC0%0/2
$MooX::TaggedAttributes::TAGCACHE{$class} //= "MooX::TaggedAttributes::Cache"->new($class)
$MooX::TaggedAttributes::TAGCACHE{$class} "MooX::TaggedAttributes::Cache"->new($class)
Truth table33%1/3
A //= B
A= $MooX::TaggedAttributes::TAGCACHE{$class}B= "MooX::TaggedAttributes::Cache"->new($class)
ABresult
1X1
011
000
83 //= MooX::TaggedAttributes::Cache->new( $class );
84 }
85  
86 else {
87 52 $class = $_[0];
88 52 ▶ return $MooX::TaggedAttributes::TAGCACHE{$class}
Condition33%1/3
$MooX::TaggedAttributes::TAGCACHE{$class} // "MooX::TaggedAttributes::Cache"->new($class)
l!l&&r!l&&!r
0520
MC/DC0%0/2
$MooX::TaggedAttributes::TAGCACHE{$class} // "MooX::TaggedAttributes::Cache"->new($class)
$MooX::TaggedAttributes::TAGCACHE{$class} "MooX::TaggedAttributes::Cache"->new($class)
Truth table33%1/3
A // B
A= $MooX::TaggedAttributes::TAGCACHE{$class}B= "MooX::TaggedAttributes::Cache"->new($class)
ABresult
1X1
011
000
89 // MooX::TaggedAttributes::Cache->new( $class );
90 }
91  
92 }
93  
94 6 1;
95  
96 __END__
« TaggedAttributes/Cache.pm ↑ Summary TaggedAttributes/Propagate.pm »