MooX/LvalueAttribute.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 66.6% 4 / 6 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 71.1% 32 / 45 CC 7 SCAR 20.0
CC
7
Cov
78%
import
8.3
BEGIN
1.0
CRAP 7.4
« Method/Generate/Accessor/Role/LvalueAttribute.pm ↑ Summary
1 #
2 # This file is part of MooX-LvalueAttribute
3 #
4 # This software is copyright (c) 2013 by Damien "dams" Krotkine.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package MooX::LvalueAttribute;
10 {
11 5 $MooX::LvalueAttribute::VERSION = '0.16';
12 }
13 5 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: Provides Lvalue accessors to Moo class attributes
16  
17 5 require Moo;
18 5 require Moo::Role;
19  
20 5 our %INJECTED_IN_ROLE;
21 5 our %INJECTED_IN_CLASS;
22  
23 4 ▶sub import {
Subroutine import: called CC=7 SCAR=21.1
24 4 my $class = shift;
25 4 my $target = caller;
26  
27 4 ▶ if ($Moo::Role::INFO{$target} && $Moo::Role::INFO{$target}{is_role}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{'is_role'}) { } 2 2 4
elsif ($Moo::MAKERS{$target} and $Moo::MAKERS{$target}{'is_class'}) { } 2 0 2
Condition66%2/3
$Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{"is_role"}
!ll&&!rl&&r
202
MC/DC50%1/2
$Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{"is_role"}
$Moo::Role::INFO{$target} $Moo::Role::INFO{$target}{"is_role"}
Truth table66%2/3
A and B
A= $Moo::Role::INFO{$target}B= $Moo::Role::INFO{$target}{"is_role"}
ABresult
0X0
100
111
28  
29 # We are loaded from a Moo role
30 2 ▶ $Moo::Role::INFO{$target}{accessor_maker} ||= do {
Condition33%1/3
$Moo::Role::INFO{$target}{"accessor_maker"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
l!l&&r!l&&!r
020
MC/DC0%0/2
$Moo::Role::INFO{$target}{"accessor_maker"} ||= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
$Moo::Role::INFO{$target}{"accessor_maker"} do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
Truth table33%1/3
A ||= B
A= $Moo::Role::INFO{$target}{"accessor_maker"}B= do { require Method::Generate::Accessor; "Method::Generate::Accessor"->new }
ABresult
1X1
011
000
31 2 require Method::Generate::Accessor;
32 2 Method::Generate::Accessor->new
33 };
34 Moo::Role->apply_roles_to_object(
35 $Moo::Role::INFO{$target}{accessor_maker},
36 2 'Method::Generate::Accessor::Role::LvalueAttribute',
37 );
38 2 $INJECTED_IN_ROLE{$target} = 1;
39  
40 ▶ } elsif ($Moo::MAKERS{$target} && $Moo::MAKERS{$target}{is_class}) {
Condition33%1/3
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
!ll&&!rl&&r
002
MC/DC0%0/2
$Moo::MAKERS{$target} and $Moo::MAKERS{$target}{"is_class"}
$Moo::MAKERS{$target} $Moo::MAKERS{$target}{"is_class"}
Truth table33%1/3
A and B
A= $Moo::MAKERS{$target}B= $Moo::MAKERS{$target}{"is_class"}
ABresult
0X0
100
111
41  
42 # We are loaded from a Moo class
43 2 ▶ if ( !$INJECTED_IN_CLASS{$target} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $INJECTED_IN_CLASS{$target}) 2 0 2
44 2 Moo::Role->apply_roles_to_object(
45 Moo->_accessor_maker_for($target),
46 'Method::Generate::Accessor::Role::LvalueAttribute',
47 );
48 2 $INJECTED_IN_CLASS{$target} = 1;
49 }
50 } else {
51 0 die "MooX::LvalueAttribute can only be used in Moo classes or Moo roles.";
52 }
53  
54 }
55  
56  
57 5 1;
58  
59 __END__
« Method/Generate/Accessor/Role/LvalueAttribute.pm ↑ Summary