TypeTiny/Role/GenerateAccessor.pm

filter: Statementstmt 100% 41 / 41 Branchbran 91.6% 11 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 89.8% 62 / 69 CC 11 SCAR 15.9
CC
11
Cov
93%
__ANON__
7.0
__ANON__
5.1
BEGIN
1.0
CRAP 4.9
↑ Summary TypeTiny.pm »
1 package MooX::TypeTiny::Role::GenerateAccessor;
2 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Sub::Quote qw(quotify sanitize_identifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶around _generate_isa_check => sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
7 $Error::TypeTiny::CarpInternal{$_} = 1
8 12 for grep /\A(?:MooX?|Method::Generate)::/, keys %Carp::CarpInternal;
9  
10 12 my $orig = shift;
11 12 my $self = shift;
12 12 my ($name, $value, $check, $init_arg) = @_;
13 12 ▶ return $self->$orig(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($check) and $check->isa("Type::Tiny") 0 12 12
Condition33%1/3
builtin::blessed($check) and $check->isa("Type::Tiny")
!ll&&!rl&&r
0012
MC/DC0%0/2
builtin::blessed($check) and $check->isa("Type::Tiny")
builtin::blessed($check) $check->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($check)B= $check->isa("Type::Tiny")
ABresult
0X0
100
111
14 unless blessed $check && $check->isa('Type::Tiny');
15  
16 12 my $var = '$isa_check_for_'.sanitize_identifier($name);
17 12 $self->{captures}->{$var} = \$check;
18  
19 12 ▶ my $varname = defined $init_arg
Branch: 1 branch
BranchTrueFalseTotal
defined $init_arg ? : 7 5 12
20 ? sprintf('$args->{%s}', quotify($init_arg))
21 : sprintf('$self->{%s}', quotify($name));
22  
23 12 my $assertion = $check->inline_assert(
24 $value,
25 $var,
26 mgaca => 0,
27 attribute_name => $name,
28 attribute_step => 'isa check',
29 varname => $varname,
30 );
31 12 $assertion =~ s/;\z//;
32 12 return $assertion;
33 6 };
34  
35 11 ▶around _generate_coerce => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
36 $Error::TypeTiny::CarpInternal{$_} = 1
37 11 for grep /\A(?:MooX?|Method::Generate)::/, keys %Carp::Internal;
38  
39 11 my $orig = shift;
40 11 my $self = shift;
41 11 my ($name, $value, $coerce, $init_arg) = @_;
42 11 ▶ return $self->$orig(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($coerce) and $coerce->isa("Type::Coercion") 1 10 11
Condition66%2/3
builtin::blessed($coerce) and $coerce->isa("Type::Coercion")
!ll&&!rl&&r
1010
MC/DC50%1/2
builtin::blessed($coerce) and $coerce->isa("Type::Coercion")
builtin::blessed($coerce) $coerce->isa("Type::Coercion")
Truth table66%2/3
A and B
A= builtin::blessed($coerce)B= $coerce->isa("Type::Coercion")
ABresult
0X0
100
111
43 unless blessed $coerce && $coerce->isa('Type::Coercion');
44  
45 10 my $var = '$coercion_for_'.sanitize_identifier($name);
46 10 $self->{captures}->{$var} = \$coerce;
47  
48 10 my $need_temp = !$self->_is_simple_value($value);
49 10 my $inline_value = $value;
50 10 ▶ if ($need_temp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_temp) 6 4 10
51 6 $inline_value = $value;
52 6 $value = '$tmp';
53 }
54  
55 10 ▶ my $code = $coerce->can_be_inlined ? $coerce->inline_coercion($value) : "${var}->coerce(${value})";
Branch: 1 branch
BranchTrueFalseTotal
$coerce->can_be_inlined ? : 2 8 10
56  
57 10 ▶ if ($need_temp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_temp) { } 6 4 10
58 6 return "do { my \$tmp = $inline_value; $code }";
59 }
60 else {
61 4 return $code;
62 }
63 6 };
64  
65 # this doesn't need to be perfect. false negatives are fine.
66 10 ▶sub _is_simple_value {
Subroutine _is_simple_value: called CC=1 SCAR=0.0
67 10 my ($self, $value) = @_;
68 10 return $value =~ /\A(?:
69 \$\w+(?:(?:->)?(?:\[[0-9]+\]|\{\w+\}))?
70 |
71 [-0-9_.ex]+
72 |
73 "[^\$\@"]*"
74 |
75 '[^']*'
76 |
77 undef\(\)
78 |
79 \(!1\)
80 )\z/x;
81 }
82  
83 6 1;
↑ Summary TypeTiny.pm »