CHI/Types.pm

filter: Statementstmt 75.3% 55 / 73 Branchbran 54.5% 12 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.0% 19 / 26 Podpod 0.0% 0 / 4 totaltotal 68.8% 86 / 125 SCAR 27.5
CC
12
Cov
71%
_build_data_serializer
6.0
_build_digester
6.0
to_Serializer
3.8
CRAP 15.7
« CHI/CacheObject.pm ↑ Summary CHI/Test/Util.pm »
1 package CHI::Types;
2 20 $CHI::Types::VERSION = '0.59';
3 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use CHI::Util qw(can_load parse_duration parse_memory_size);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use MooX::Types::MooseLike qw(exception_message);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use MooX::Types::MooseLike::Numeric qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 our @EXPORT_OK = ();
13 20 our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
14  
15 MooX::Types::MooseLike::register_types(
16 [
17 {
18 name => 'OnError',
19 test => sub {
20 1999 ▶ ref( $_[0] ) eq 'CODE' || $_[0] =~ /^(?:ignore|warn|die|log)$/;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "CODE" or $_[0] =~ /^(?:ignore|warn|die|log)$/ 1997 2 1999
21 },
22 message => sub {
23 2 ▶ return exception_message( $_[0], 'a coderef or error level' );
Subroutine __ANON__: called CC=1 SCAR=0.0
24 },
25 inflate => 0,
26 },
27 {
28 name => 'Duration',
29 subtype_of => PositiveInt,
30 26 ▶ test => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 message =>
32 0 ▶ sub { return exception_message( $_[0], 'a positive integer' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 inflate => 0,
34 },
35 {
36 name => 'MemorySize',
37 subtype_of => PositiveInt,
38 111 ▶ test => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 message =>
40 0 ▶ sub { return exception_message( $_[0], 'a positive integer' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 inflate => 0,
42 },
43 {
44 name => 'DiscardPolicy',
45 60 ▶ test => sub { !ref( $_[0] ) || ref( $_[0] ) eq 'CODE' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[0] or ref $_[0] eq "CODE" 14 46 60
46 message => sub {
47 0 ▶ return exception_message( $_[0], 'a coderef or policy name' );
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 },
49 inflate => 0,
50 },
51 {
52 name => 'Serializer',
53 subtype_of => Object,
54 1905 ▶ test => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
55 message => sub {
56 0 ▶ return exception_message( $_[0],
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 'a serializer, hashref, or string' );
58 },
59 inflate => 0,
60 },
61 {
62 name => 'Digester',
63 subtype_of => Object,
64 1000 ▶ test => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 message => sub {
66 0 ▶ return exception_message( $_[0],
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 'a digester, hashref, or string' );
68 },
69 20 inflate => 0,
70 }
71 ],
72 __PACKAGE__
73 );
74  
75 sub to_MemorySize {
76 111 ▶ my $from = shift;
Subroutine to_MemorySize: called CC=3 SCAR=11.3
Pod undocumented
77 111 ▶ if ( is_Num($from) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_Num($from)) { } 104 7 111
elsif (is_Str($from)) { } 7 0 7
78 104 $from;
79 }
80 elsif ( is_Str($from) ) {
81 7 parse_memory_size($from);
82 }
83 else {
84 0 $from;
85 }
86 }
87 20 push @EXPORT_OK, 'to_MemorySize';
88  
89 sub to_Duration {
90 26 ▶ my $from = shift;
Subroutine to_Duration: called CC=2 SCAR=7.6
Pod undocumented
91 26 ▶ if ( is_Str($from) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_Str($from)) { } 26 0 26
92 26 parse_duration($from);
93 }
94 else {
95 0 $from;
96 }
97 }
98 20 push @EXPORT_OK, 'to_Duration';
99  
100 sub to_Serializer {
101 1905 ▶ my $from = shift;
Subroutine to_Serializer: called CC=3 SCAR=13.3
Pod undocumented
102 1905 ▶ if ( is_HashRef($from) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_HashRef($from)) { } 0 1905 1905
elsif (is_Str($from)) { } 0 1905 1905
103 0 _build_data_serializer($from);
104 }
105 elsif ( is_Str($from) ) {
106 0 _build_data_serializer( { serializer => $from, raw => 1 } );
107 }
108 else {
109 1905 $from;
110 }
111 }
112 20 push @EXPORT_OK, 'to_Serializer';
113  
114 sub to_Digester {
115 1000 ▶ my $from = shift;
Subroutine to_Digester: called CC=3 SCAR=13.3
Pod undocumented
116 1000 ▶ if ( is_HashRef($from) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_HashRef($from)) { } 0 1000 1000
elsif (is_Str($from)) { } 0 1000 1000
117 0 _build_digester(%$from);
118 }
119 elsif ( is_Str($from) ) {
120 0 _build_digester($from);
121 }
122 else {
123 1000 $from;
124 }
125 }
126 20 push @EXPORT_OK, 'to_Digester';
127  
128 20 my $data_serializer_loaded = can_load('Data::Serializer');
129  
130 sub _build_data_serializer {
131 0 ▶ my ($params) = @_;
Subroutine _build_data_serializer: not called CC=2 SCAR=17.9
132  
133 0 ▶ if ($data_serializer_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_serializer_loaded) { } 0 0 0
134 0 return Data::Serializer->new(%$params);
135 }
136 else {
137 0 croak
138 "Could not load Data::Serializer - install Data::Serializer from CPAN to support serializer argument";
139 }
140 }
141  
142 20 my $digest_loaded = can_load('Digest');
143  
144 sub _build_digester {
145 0 ▶ if ($digest_loaded) {
Subroutine _build_digester: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($digest_loaded) { } 0 0 0
146 0 return Digest->new(@_);
147 }
148 else {
149 0 croak "Digest could not be loaded, cannot handle digester argument";
150 }
151 }
152  
153 20 1;
« CHI/CacheObject.pm ↑ Summary CHI/Test/Util.pm »