Usul/Types.pm

filter: Statementstmt 73.6% 95 / 129 Branchbran 27.7% 10 / 36 Conditioncond 3.7% 1 / 27 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 54.7% 29 / 53 Podpod n/a totaltotal 51.3% 135 / 263 CC 31 SCAR 16.2
CC
31
Cov
55%
__ANON__
12.0
__ANON__
12.0
__ANON__
12.0
CRAP 5.1
« Usul/Config.pm ↑ Summary Usul/Options.pm »
1 package Class::Usul::Types;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Class::Usul::Constants qw( DEFAULT_ENCODING FALSE LOG_LEVELS NUL TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Class::Usul::Functions qw( ensure_class_loaded exception untaint_cmdline );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use Encode qw( find_encoding );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Scalar::Util qw( blessed tainted );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Type::Library -base, -declare =>
Subroutine BEGIN: called CC=1 SCAR=0.0
12 qw( ConfigProvider DataEncoding DataLumper
13 DateTimeRef Localiser Locker Logger
14 24 NullLoadingClass Plinth ProcCommer );
15 24 ▶use Type::Utils qw( as class_type coerce extends
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 from message subtype via where );
17 24 ▶use Unexpected::Functions qw( inflate_message is_class_loaded );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 24 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 24 ▶BEGIN { extends q(Unexpected::Types) };
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # Private functions
24 0 ▶my $_exception_message_for_object_reference = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 return inflate_message 'String [_1] is not an object reference', $_[ 0 ];
26 24 };
27  
28 0 ▶my $_exception_message_for_configprovider = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
29 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing some configuration attributes", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
30 'Object [_1] is missing some configuration attributes', blessed $_[ 0 ];
31  
32 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
33 24 };
34  
35 0 ▶my $_exception_message_for_datetime = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
36 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is not of class DateTime", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
37 'Object [_1] is not of class DateTime', blessed $_[ 0 ];
38  
39 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
40 24 };
41  
42 0 ▶my $_exception_message_for_datalumper = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
43 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing the \"data_load\" method", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
44 'Object [_1] is missing the "data_load" method', blessed $_[ 0 ];
45  
46 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
47 24 };
48  
49 0 ▶my $_exception_message_for_localiser = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
50 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing the localize method", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
51 'Object [_1] is missing the localize method', blessed $_[ 0 ];
52  
53 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
54 24 };
55  
56 0 ▶my $_exception_message_for_locker = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
57 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing set / reset methods", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
58 'Object [_1] is missing set / reset methods', blessed $_[ 0 ];
59  
60 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
61 24 };
62  
63 0 ▶my $_exception_message_for_logger = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
64 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing a log level method", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
65 'Object [_1] is missing a log level method', blessed $_[ 0 ];
66  
67 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
68 24 };
69  
70 0 ▶my $_exception_message_for_plinth = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
71 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing some builder attributes", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
72 'Object [_1] is missing some builder attributes', blessed $_[ 0 ];
73  
74 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
75 24 };
76  
77 0 ▶my $_exception_message_for_proccommer = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
78 0 ▶ $_[ 0 ] and blessed $_[ 0 ] and return inflate_message
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and builtin::blessed($_[0]) and return &inflate_message("Object [_1] is missing the \"run_cmd\" method", scalar builtin::blessed($_[0])) 0 0 0
Condition0%0/3
$_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and builtin::blessed($_[0])
$_[0] builtin::blessed($_[0])
Truth table0%0/3
A and B
A= $_[0]B= builtin::blessed($_[0])
ABresult
0X0
100
111
79 'Object [_1] is missing the "run_cmd" method', blessed $_[ 0 ];
80  
81 0 return $_exception_message_for_object_reference->( $_[ 0 ] );
82 24 };
83  
84 0 ▶my $_has_builder_attributes = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
85 0 my $obj = shift;
86  
87 0 ▶ $obj->can( $_ ) or return FALSE for (qw( config debug l10n lock log ));
Branch: 1 branch
BranchTrueFalseTotal
$obj->can($_) or return 0 0 0 0
88  
89 0 return TRUE;
90 24 };
91  
92 406 ▶my $_has_log_level_methods = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
93 406 my $obj = shift;
94  
95 406 ▶ $obj->can( $_ ) or return FALSE for (LOG_LEVELS);
Branch: 1 branch
BranchTrueFalseTotal
$obj->can($_) or return 0 2436 0 2436
96  
97 406 return TRUE;
98 24 };
99  
100 40 ▶my $_has_min_config_attributes = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
101 40 my $obj = shift; my @config_attr = ( qw(appldir home root tempdir vardir) );
102  
103 40 ▶ $obj->can( $_ ) or return FALSE for (@config_attr);
Branch: 1 branch
BranchTrueFalseTotal
$obj->can($_) or return 0 200 0 200
104  
105 40 return TRUE;
106 24 };
107  
108 75 ▶my $_isa_untainted_encoding = sub {
Subroutine __ANON__: called CC=1 SCAR=0.5
109 75 my $enc = shift; my $res;
110  
111 75 ▶ try { $res = !tainted( $enc ) && find_encoding( $enc ) ? TRUE : FALSE }
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
!&tainted($enc) && &find_encoding($enc) ? : 75 0 75
Condition33%1/3
not &tainted($enc) and &find_encoding($enc)
!ll&&!rl&&r
0075
MC/DC0%0/2
not &tainted($enc) and &find_encoding($enc)
not &tainted($enc) &find_encoding($enc)
Truth table33%1/3
not(A) and B
A= not &tainted($enc)B= &find_encoding($enc)
ABresult
0X0
100
111
112 0 ▶ catch { $res = FALSE };
Subroutine __ANON__: not called CC=1 SCAR=1.2
113  
114 75 return $res
115 24 };
116  
117 2 ▶my $_load_if_exists = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
118 2 ▶ if (my $class = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = shift()) 2 0 2
119 2 ▶ eval { ensure_class_loaded( $class ) }; exception or return $class;
Branch: 1 branch
BranchTrueFalseTotal
&exception() or return $class 1 1 2
120 }
121  
122 1 ensure_class_loaded 'Class::Null'; return 'Class::Null';
123 24 };
124  
125 3 ▶my $_str2date_time = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
126 3 my $str = shift; ensure_class_loaded 'Class::Usul::Time';
127  
128 3 return Class::Usul::Time::str2date_time( $str );
129 24 };
130  
131 # Type definitions
132 subtype ConfigProvider, as Object,
133 40 ▶ where { $_has_min_config_attributes->( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
134 0 ▶ message { $_exception_message_for_configprovider->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
135  
136 subtype DataEncoding, as Str,
137 75 ▶ where { $_isa_untainted_encoding->( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
138 0 ▶ message { inflate_message 'String [_1] is not a valid encoding', $_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
139  
140 coerce DataEncoding,
141 0 ▶ from Str, via { untaint_cmdline $_ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 0 ▶ from Undef, via { DEFAULT_ENCODING };
Subroutine __ANON__: not called CC=1 SCAR=1.2
143  
144 subtype DataLumper, as Object,
145 4 ▶ where { $_->can( 'data_load' ) and $_->can( 'data_dump' ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_->can("data_load") and $_->can("data_dump") 4 0 4
146 0 ▶ message { $_exception_message_for_datalumper->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
147  
148 subtype DateTimeRef, as Object,
149 1 ▶ where { blessed $_ && $_->isa( 'DateTime' ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->isa("DateTime") 1 0 1
150 0 ▶ message { $_exception_message_for_datetime->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
151  
152 3 ▶coerce DateTimeRef, from Str, via { $_str2date_time->( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
153  
154 subtype Localiser, as Object,
155 4 ▶ where { $_->can( 'localize' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
156 0 ▶ message { $_exception_message_for_localiser->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
157  
158 subtype Locker, as Object,
159 11 ▶ where { $_->can( 'set' ) and $_->can( 'reset' ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_->can("set") and $_->can("reset") 11 0 11
160 0 ▶ message { $_exception_message_for_locker->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
161  
162 subtype Logger, as Object,
163 406 ▶ where { $_->isa( 'Class::Null' ) or $_has_log_level_methods->( $_ ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("Class::Null") or &$_has_log_level_methods($_) 0 406 406
164 0 ▶ message { $_exception_message_for_logger->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
165  
166 subtype NullLoadingClass, as ClassName,
167 2 ▶ where { is_class_loaded( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
168  
169 coerce NullLoadingClass,
170 2 ▶ from Str, via { $_load_if_exists->( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
171 0 ▶ from Undef, via { $_load_if_exists->( NUL ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
172  
173 subtype Plinth, as Object,
174 0 ▶ where { $_has_builder_attributes->( $_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
175 0 ▶ message { $_exception_message_for_plinth->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
176  
177 subtype ProcCommer, as Object,
178 13 ▶ where { $_->can( 'run_cmd' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
179 0 ▶ message { $_exception_message_for_proccommer->( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
180  
181 24 1;
182  
183 __END__
« Usul/Config.pm ↑ Summary Usul/Options.pm »