AttributeTags.pm

filter: Statementstmt 94.7% 54 / 57 Branchbran 50.0% 7 / 14 Conditioncond 37.5% 3 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 80.0% 76 / 95 CC 12 SCAR 17.2
CC
12
Cov
81%
_canonicalize_attribute_spec
12.3
import
5.0
Baz
2.1
CRAP 5.6
↑ Summary AttributeTags/PRole.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package MooseX::AttributeTags;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.005';
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::OptList qw(mkopt);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 my $subname = eval { require Sub::Name; 'Sub::Name'->can('subname') }
15 1 ▶ || do { require Sub::Util; 'Sub::Util'->can('set_subname') };
Condition33%1/3
eval { do { require Sub::Name; 'Sub::Name'->can('subname') } } || do { require Sub::Util; 'Sub::Util'->can('set_subname') }
l!l&&r!l&&!r
010
MC/DC0%0/2
eval { do { require Sub::Name; 'Sub::Name'->can('subname') } } || do { require Sub::Util; 'Sub::Util'->can('set_subname') }
eval { do { require Sub::Name; 'Sub::Name'->can('subname') } } do { require Sub::Util; 'Sub::Util'->can('set_subname') }
Truth table33%1/3
A || B
A= eval { do { require Sub::Name; 'Sub::Name'->can('subname') } }B= do { require Sub::Util; 'Sub::Util'->can('set_subname') }
ABresult
1X1
011
000
16  
17 1 my $yah = 1; # avoid exported subs becoming constants
18  
19 sub import
20 1 ▶{
Subroutine import: called CC=5 SCAR=16.1
21 1 my $caller = caller;
22 1 my $class = shift;
23 1 my $opts = mkopt(\@_);
24 1 my $prole = $class->_prole;
25
26 1 for (@$opts)
27 {
28 3 my ($traitname, $traitdesc) = @$_;
29 3 ▶ $traitdesc ||= [];
Condition100%2/2
$traitdesc ||= []
l!l
21
MC/DC100%1/1
$traitdesc ||= []
$traitdesc
Truth table100%2/2
A
A= $traitdesc
Aresult
11
00
30 3 ▶ ref($traitdesc) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $traitdesc eq "ARRAY" or croak("Expected arrayref, not $traitdesc; stopped") 3 0 3
31 or croak("Expected arrayref, not $traitdesc; stopped");
32
33 3 my %attrs;
34 3 my $inner_opts = mkopt($traitdesc);
35 3 for (@$inner_opts)
36 {
37 4 my ($attrname, $attrdesc) = @$_;
38 4 $attrs{$attrname} = $class->_canonicalize_attribute_spec($attrdesc);
39 }
40
41 3 my $traitqname = sprintf('%s::%s', $caller, $traitname);
42 3 my $trait = $prole->generate_role(
43 package => $traitqname,
44 parameters => { attributes => \%attrs },
45 );
46
47 3 ▶ my $coderef = $subname->($traitqname, sub () { $traitqname if $yah });
Subroutine Baz: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $yah 5 0 5
48 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 3 *$traitqname = $coderef;
50 }
51 }
52  
53 sub _prole
54 1 ▶{
Subroutine _prole: called CC=1 SCAR=0.0
55 1 require MooseX::AttributeTags::PRole;
56 1 Class::MOP::class_of('MooseX::AttributeTags::PRole');
57 }
58  
59 sub _canonicalize_attribute_spec
60 4 ▶{
Subroutine _canonicalize_attribute_spec: called CC=7 SCAR=25.1
61 4 shift;
62 4 my $spec = $_[0];
63
64 4 ▶ return [ is => 'ro' ]
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 0 4 4
65 unless defined $spec;
66
67 4 ▶ return $spec
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec eq "ARRAY" 3 1 4
68 if ref $spec eq 'ARRAY';
69
70 1 ▶ return [ %$spec ]
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec eq "HASH" 0 1 1
71 if ref $spec eq 'HASH';
72
73 1 ▶ return [ is => 'ro', lazy => 1, default => $spec ]
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec eq "CODE" 1 0 1
74 if ref $spec eq 'CODE';
75
76 0 ▶ return [ is => 'ro', isa => $spec ]
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($spec) and $spec->isa("Moose::Meta::TypeConstraint") 0 0 0
Condition0%0/3
builtin::blessed($spec) and $spec->isa("Moose::Meta::TypeConstraint")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($spec) and $spec->isa("Moose::Meta::TypeConstraint")
builtin::blessed($spec) $spec->isa("Moose::Meta::TypeConstraint")
Truth table0%0/3
A and B
A= builtin::blessed($spec)B= $spec->isa("Moose::Meta::TypeConstraint")
ABresult
0X0
100
111
77 if blessed($spec) && $spec->isa('Moose::Meta::TypeConstraint');
78
79 0 croak("Expected coderef/arrayref/hashref/constraint, not $spec; stopped");
80 }
81  
82 1 1;
83  
84 __END__
↑ Summary AttributeTags/PRole.pm »