Unexpected/Types.pm

filter: Statementstmt 84.8% 73 / 86 Branchbran 58.3% 7 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 30 / 42 Podpod n/a totaltotal 75.8% 110 / 145 CC 8 SCAR 6.3
CC
8
Cov
79%
__ANON__
8.7
__ANON__
3.7
__ANON__
3.0
CRAP 1.9
« Unexpected/TraitFor/Throwing.pm ↑ Summary Unexpected.pm »
1 package Unexpected::Types;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Module::Runtime qw( is_module_name require_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Type::Library -base, -declare =>
Subroutine BEGIN: called CC=1 SCAR=0.0
10 qw( LoadableClass NonEmptySimpleStr
11 NonNumericSimpleStr NonZeroPositiveInt
12 NonZeroPositiveNum PositiveInt PositiveNum
13 4 RequestFactory SimpleStr Tracer );
14 4 ▶use Type::Utils qw( as coerce extends from
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 inline_as message subtype via where );
16 4 ▶use Unexpected::Functions qw( inflate_message );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶BEGIN { extends 'Types::Standard' };
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 my $LOADABLE_CLASS_ERROR;
21  
22 4 $Error::TypeTiny::CarpInternal{ 'Method::Generate::Accessor' }++;
23 4 $Error::TypeTiny::CarpInternal{ 'Method::Generate::Constructor' }++;
24 4 $Error::TypeTiny::CarpInternal{ 'Sub::Quote' }++;
25 4 $Error::TypeTiny::CarpInternal{ 'Unexpected::TraitFor::Throwing' }++;
26  
27 # Private functions
28 36 ▶my $_constraint_for_loadable_class = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
29 36 ▶ my $class = shift; is_module_name( $class ) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&is_module_name($class) or return 0 34 2 36
30  
31 34 local $EVAL_ERROR; eval { require_module( $class ) };
32  
33 34 $LOADABLE_CLASS_ERROR = $EVAL_ERROR;
34  
35 34 ▶ return $EVAL_ERROR ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$Unexpected::Types::EVAL_ERROR ? : 2 32 34
36 4 };
37  
38 2 ▶my $_exception_message_for_object_reference = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 2 return inflate_message( 'String [_1] is not an object reference', $_[ 0 ] );
40 4 };
41  
42 2 ▶my $_exception_message_for_req_factory = sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
43 2 ▶ blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing the new_from_simple_request method", scalar builtin::blessed($_[0])) 2 0 2
44 'Object [_1] is missing the new_from_simple_request method',
45 blessed $_[ 0 ];
46  
47 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
48 4 };
49  
50 4 ▶my $_exception_message_for_tracer = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 4 ▶ blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing a frames method", scalar builtin::blessed($_[0])) 2 2 4
52 'Object [_1] is missing a frames method', blessed $_[ 0 ];
53  
54 2 return $_exception_message_for_object_reference->( $_[ 0 ] );
55 4 };
56  
57 # Types
58 subtype NonEmptySimpleStr, as Str,
59 11 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 11 $_[ 0 ]->parent->inline_check( $_ )
61 ." and length $_ > 0 and length $_ < 255 and $_ !~ m{ [\\n] }mx" },
62 5 ▶ message {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 5 inflate_message
64 ( 'Attribute value [_1] is not a non empty simple string', $_ ) },
65 0 ▶ where { length $_ > 0 and length $_ < 255 and $_ !~ m{ [\n] }mx };
Subroutine __ANON__: not called CC=3 SCAR=21.6
Branch: 1 branch
BranchTrueFalseTotal
length $_ > 0 and length $_ < 255 and not $_ =~ / [\n] /mx 0 0 0
Condition0%0/3
length $_ > 0 and length $_ < 255
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ > 0 and length $_ < 255
length $_ > 0 length $_ < 255
Truth table0%0/3
A and B
A= length $_ > 0B= length $_ < 255
ABresult
0X0
100
111
66  
67 subtype NonZeroPositiveInt, as Int,
68 13 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ > 0" },
Subroutine __ANON__: called CC=1 SCAR=0.0
69 6 ▶ message {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 6 inflate_message
71 ( 'Attribute value [_1] is not a non zero positive integer', $_ ) },
72 0 ▶ where { $_ > 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
73  
74 subtype NonZeroPositiveNum, as Num,
75 11 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ > 0" },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 6 ▶ message {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 6 inflate_message
78 ( 'Attribute value [_1] is not a non zero positive number', $_ ) },
79 0 ▶ where { $_ > 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
80  
81 subtype PositiveInt, as Int,
82 8 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ >= 0" },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 0 ▶ message { inflate_message
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 ( 'Attribute value [_1] is not a positive integer', $_ ) },
85 0 ▶ where { $_ >= 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
86  
87 subtype PositiveNum, as Num,
88 8 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ >= 0" },
Subroutine __ANON__: called CC=1 SCAR=0.0
89 0 ▶ message { inflate_message
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 ( 'Attribute value [_1] is not a positive number', $_ ) },
91 0 ▶ where { $_ >= 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
92  
93 subtype RequestFactory, as Object,
94 10 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )
Subroutine __ANON__: called CC=1 SCAR=0.0
95 ." and $_->can( 'new_from_simple_request' )" },
96 2 ▶ message { $_exception_message_for_req_factory->( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 0 ▶ where { $_->can( 'new_from_simple_request' ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
98  
99 subtype SimpleStr, as Str,
100 20 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )
Subroutine __ANON__: called CC=1 SCAR=0.0
101 ." and length $_ < 255 and $_ !~ m{ [\\n] }mx" },
102 0 ▶ message { inflate_message
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 ( 'Attribute value [_1] is not a simple string', $_ ) },
104 0 ▶ where { length $_ < 255 and $_ !~ m{ [\n] }mx };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
length $_ < 255 and not $_ =~ / [\n] /mx 0 0 0
105  
106 subtype Tracer, as Object,
107 13 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_->can( 'frames' )" },
Subroutine __ANON__: called CC=1 SCAR=0.0
108 4 ▶ message { $_exception_message_for_tracer->( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 0 ▶ where { $_->can( 'frames' ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
110  
111  
112 subtype LoadableClass, as NonEmptySimpleStr,
113 4 ▶ message { inflate_message( 'String [_1] is not a loadable class: [_2]',
Subroutine __ANON__: called CC=1 SCAR=0.0
114 $_, $LOADABLE_CLASS_ERROR ) },
115 36 ▶ where { $_constraint_for_loadable_class->( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
116  
117 subtype NonNumericSimpleStr, as SimpleStr,
118 10 ▶ inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ !~ m{ \\d+ }mx" },
Subroutine __ANON__: called CC=1 SCAR=0.0
119 3 ▶ message {
Subroutine __ANON__: called CC=1 SCAR=0.0
120 3 inflate_message
121 ( 'Attribute value [_1] is not a non numeric simple string', $_ ) },
122 0 ▶ where { $_ !~ m{ \d+ }mx };
Subroutine __ANON__: not called CC=1 SCAR=1.2
123  
124 4 1;
125  
126 __END__
« Unexpected/TraitFor/Throwing.pm ↑ Summary Unexpected.pm »