blib/lib/Error/TypeTiny/Assertion.pm

filter: Statementstmt 100% 53 / 53 Branchbran 72.7% 16 / 22 Conditioncond 64.2% 9 / 14 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 17 / 17 Podpod 100% 11 / 11 totaltotal 87.9% 109 / 124 CC 18 SCAR 14.6
CC
18
Cov
88%
new
8.6
__ANON__
7.1
_build_message
2.1
CRAP 4.3
« lib/Types/Standard/HashRef.pm ↑ Summary blib/lib/Type/Tiny/Duck.pm »
1 package Error::TypeTiny::Assertion;
2  
3 286 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 286 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 286 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 286 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 286 $Error::TypeTiny::Assertion::AUTHORITY = 'cpan:TOBYINK';
9 286 $Error::TypeTiny::Assertion::VERSION = '2.010001';
10 }
11  
12 286 $Error::TypeTiny::Assertion::VERSION =~ tr/_//d;
13  
14 286 require Error::TypeTiny;
15 286 our @ISA = 'Error::TypeTiny';
16  
17 368 ▶sub type { $_[0]{type} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
18 364 ▶sub value { $_[0]{value} }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
19 1020 ▶sub varname { $_[0]{varname} ||= '$_' }
Subroutine varname: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"varname"} ||= "\$_"
l!l
97446
MC/DC100%1/1
$_[0]{"varname"} ||= "\$_"
$_[0]{"varname"}
Truth table100%2/2
A
A= $_[0]{"varname"}
Aresult
11
00
20 2 ▶sub attribute_step { $_[0]{attribute_step} }
Subroutine attribute_step: called CC=1 SCAR=0.0
Pod documented
21 2 ▶sub attribute_name { $_[0]{attribute_name} }
Subroutine attribute_name: called CC=1 SCAR=0.0
Pod documented
22  
23 362 ▶sub has_type { defined $_[0]{type} }; # sic
Subroutine has_type: called CC=1 SCAR=0.0
Pod documented
24 2 ▶sub has_attribute_step { exists $_[0]{attribute_step} }
Subroutine has_attribute_step: called CC=1 SCAR=0.0
Pod documented
25 2 ▶sub has_attribute_name { exists $_[0]{attribute_name} }
Subroutine has_attribute_name: called CC=1 SCAR=0.0
Pod documented
26  
27 427 ▶sub new {
Subroutine new: called CC=8 SCAR=21.6
Pod documented
28 427 my $class = shift;
29 427 my $self = $class->SUPER::new( @_ );
30
31 # Supported but undocumented parameter is `mgaca`.
32 # This indicates whether Error::TypeTiny::Assertion
33 # should attempt to figure out which attribute caused
34 # the error from Method::Generate::Accessor's info.
35 # Can be set to true/false or not set. If not set,
36 # the current behaviour is true, but this may change
37 # in the future. If set to false, will ignore the
38 # $Method::Generate::Accessor::CurrentAttribute hashref.
39 #
40
41 427 ▶ if ( ref $Method::Generate::Accessor::CurrentAttribute
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Method::Generate::Accessor::CurrentAttribute and $self->{"mgaca"} || !exists $self->{"mgaca"}) 26 401 427
Condition50%3/6
ref $Method::Generate::Accessor::CurrentAttribute and $self->{"mgaca"} || !exists $self->{"mgaca"}
!ll&&!rl&&r
401026
$self->{"mgaca"} or not exists $self->{"mgaca"}
l!l&&r!l&&!r
0260
MC/DC33%1/3
ref $Method::Generate::Accessor::CurrentAttribute and $self->{"mgaca"} || !exists $self->{"mgaca"}
ref $Method::Generate::Accessor::CurrentAttribute $self->{"mgaca"} not exists $self->{"mgaca"}
Truth table50%2/4
A and B or not(C)
A= ref $Method::Generate::Accessor::CurrentAttributeB= $self->{"mgaca"}C= not exists $self->{"mgaca"}
ABCresult
0XX0
1000
11X1
1011
42 and $self->{mgaca} || !exists $self->{mgaca} )
43 {
44 26 require B;
45 26 my %d = %{$Method::Generate::Accessor::CurrentAttribute};
46 26 ▶ $self->{attribute_name} = $d{name} if defined $d{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $d{"name"} 26 0 26
47 26 ▶ $self->{attribute_step} = $d{step} if defined $d{step};
Branch: 1 branch
BranchTrueFalseTotal
if defined $d{"step"} 26 0 26
48
49 26 ▶ if ( defined $d{init_arg} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $d{'init_arg'}) { } 21 5 26
elsif (defined $d{'name'}) { } 5 0 5
50 21 $self->{varname} = sprintf( '$args->{%s}', B::perlstring( $d{init_arg} ) );
51 }
52 elsif ( defined $d{name} ) {
53 5 $self->{varname} = sprintf( '$self->{%s}', B::perlstring( $d{name} ) );
54 }
55 } #/ if ( ref $Method::Generate::Accessor::CurrentAttribute...)
56
57 427 return $self;
58 } #/ sub new
59  
60 344 ▶sub message {
Subroutine message: called CC=2 SCAR=6.9
Pod documented
61 344 my $e = shift;
62 344 ▶ $e->varname eq '$_'
Branch: 1 branch
BranchTrueFalseTotal
$e->varname eq '$_' ? : 29 315 344
63 ? $e->SUPER::message
64 : sprintf( '%s (in %s)', $e->SUPER::message, $e->varname );
65 }
66  
67 1 ▶sub _build_message {
Subroutine _build_message: called CC=2 SCAR=7.2
68 1 my $e = shift;
69 1 ▶ $e->has_type
Branch: 1 branch
BranchTrueFalseTotal
$e->has_type ? : 1 0 1
70 ? sprintf(
71 '%s did not pass type constraint "%s"',
72 Type::Tiny::_dd( $e->value ), $e->type
73 )
74 : sprintf(
75 '%s did not pass type constraint',
76 Type::Tiny::_dd( $e->value )
77 );
78 } #/ sub _build_message
79  
80 338 ▶*to_string = sub {
Subroutine __ANON__: called CC=7 SCAR=19.7
81 338 my $e = shift;
82 338 my $msg = $e->message;
83
84 338 my $c = $e->context;
85 338 ▶ $msg .= sprintf( " at %s line %s", $c->{file} || 'file?', $c->{line} || 'NaN' )
Branch: 1 branch
BranchTrueFalseTotal
if $c 338 0 338
Condition50%2/4
$c->{'file'} || 'file?'
l!l
3380
$c->{'line'} || 'NaN'
l!l
3380
MC/DC0%0/1
$c->{'file'} || 'file?'
$c->{'file'}
MC/DC0%0/1
$c->{'line'} || 'NaN'
$c->{'line'}
Truth table50%1/2
A
A= $c->{'file'}
Aresult
11
00
Truth table50%1/2
A
A= $c->{'line'}
Aresult
11
00
86 if $c;
87
88 338 my $explain = $e->explain;
89 338 ▶ return "$msg\n" unless @{ $explain || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$explain or [];} 1 337 338
Condition100%2/2
$explain || []
l!l
3371
MC/DC100%1/1
$explain || []
$explain
Truth table100%2/2
A
A= $explain
Aresult
11
00
90
91 337 $msg .= "\n";
92 337 for my $line ( @$explain ) {
93 2063 $msg .= " $line\n";
94 }
95
96 337 return $msg;
97 }
98 286 ▶ if $] >= 5.008;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" 286 0 286
99
100 361 ▶sub explain {
Subroutine explain: called CC=2 SCAR=6.9
Pod documented
101 361 my $e = shift;
102 361 ▶ return undef unless $e->has_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $e->has_type 1 360 361
103 360 $e->type->validate_explain( $e->value, $e->varname );
104 }
105  
106 286 1;
107  
108 __END__
« lib/Types/Standard/HashRef.pm ↑ Summary blib/lib/Type/Tiny/Duck.pm »