line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::Types; |
2
|
|
|
|
|
|
|
$CHI::Types::VERSION = '0.60'; |
3
|
20
|
|
|
20
|
|
94
|
use Carp; |
|
20
|
|
|
|
|
28
|
|
|
20
|
|
|
|
|
1368
|
|
4
|
20
|
|
|
20
|
|
96
|
use CHI::Util qw(can_load parse_duration parse_memory_size); |
|
20
|
|
|
|
|
26
|
|
|
20
|
|
|
|
|
1009
|
|
5
|
20
|
|
|
20
|
|
88
|
use MooX::Types::MooseLike qw(exception_message); |
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
766
|
|
6
|
20
|
|
|
20
|
|
91
|
use MooX::Types::MooseLike::Base qw(:all); |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
7366
|
|
7
|
20
|
|
|
20
|
|
10767
|
use MooX::Types::MooseLike::Numeric qw(:all); |
|
20
|
|
|
|
|
22313
|
|
|
20
|
|
|
|
|
3879
|
|
8
|
20
|
|
|
20
|
|
128
|
use base qw(Exporter); |
|
20
|
|
|
|
|
33
|
|
|
20
|
|
|
|
|
1794
|
|
9
|
20
|
|
|
20
|
|
94
|
use strict; |
|
20
|
|
|
|
|
28
|
|
|
20
|
|
|
|
|
579
|
|
10
|
20
|
|
|
20
|
|
88
|
use warnings; |
|
20
|
|
|
|
|
26
|
|
|
20
|
|
|
|
|
14553
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = (); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
MooX::Types::MooseLike::register_types( |
16
|
|
|
|
|
|
|
[ |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
name => 'OnError', |
19
|
|
|
|
|
|
|
test => sub { |
20
|
|
|
|
|
|
|
ref( $_[0] ) eq 'CODE' || $_[0] =~ /^(?:ignore|warn|die|log)$/; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
message => sub { |
23
|
|
|
|
|
|
|
return exception_message( $_[0], 'a coderef or error level' ); |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
inflate => 0, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
name => 'Duration', |
29
|
|
|
|
|
|
|
subtype_of => PositiveInt, |
30
|
|
|
|
|
|
|
test => sub { 1 }, |
31
|
|
|
|
|
|
|
message => |
32
|
|
|
|
|
|
|
sub { return exception_message( $_[0], 'a positive integer' ) }, |
33
|
|
|
|
|
|
|
inflate => 0, |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
name => 'MemorySize', |
37
|
|
|
|
|
|
|
subtype_of => PositiveInt, |
38
|
|
|
|
|
|
|
test => sub { 1 }, |
39
|
|
|
|
|
|
|
message => |
40
|
|
|
|
|
|
|
sub { return exception_message( $_[0], 'a positive integer' ) }, |
41
|
|
|
|
|
|
|
inflate => 0, |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
name => 'DiscardPolicy', |
45
|
|
|
|
|
|
|
test => sub { !ref( $_[0] ) || ref( $_[0] ) eq 'CODE' }, |
46
|
|
|
|
|
|
|
message => sub { |
47
|
|
|
|
|
|
|
return exception_message( $_[0], 'a coderef or policy name' ); |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
inflate => 0, |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
name => 'Serializer', |
53
|
|
|
|
|
|
|
subtype_of => Object, |
54
|
|
|
|
|
|
|
test => sub { 1 }, |
55
|
|
|
|
|
|
|
message => sub { |
56
|
|
|
|
|
|
|
return exception_message( $_[0], |
57
|
|
|
|
|
|
|
'a serializer, hashref, or string' ); |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
inflate => 0, |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
name => 'Digester', |
63
|
|
|
|
|
|
|
subtype_of => Object, |
64
|
|
|
|
|
|
|
test => sub { 1 }, |
65
|
|
|
|
|
|
|
message => sub { |
66
|
|
|
|
|
|
|
return exception_message( $_[0], |
67
|
|
|
|
|
|
|
'a digester, hashref, or string' ); |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
inflate => 0, |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
], |
72
|
|
|
|
|
|
|
__PACKAGE__ |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub to_MemorySize { |
76
|
96
|
|
|
96
|
0
|
4884
|
my $from = shift; |
77
|
96
|
100
|
|
|
|
307
|
if ( is_Num($from) ) { |
|
|
50
|
|
|
|
|
|
78
|
90
|
|
|
|
|
2354
|
$from; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ( is_Str($from) ) { |
81
|
6
|
|
|
|
|
154
|
parse_memory_size($from); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
$from; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_MemorySize'; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub to_Duration { |
90
|
23
|
|
|
23
|
0
|
475
|
my $from = shift; |
91
|
23
|
50
|
|
|
|
84
|
if ( is_Str($from) ) { |
92
|
23
|
|
|
|
|
256
|
parse_duration($from); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
|
|
|
|
0
|
$from; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_Duration'; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub to_Serializer { |
101
|
1673
|
|
|
1673
|
0
|
10006
|
my $from = shift; |
102
|
1673
|
50
|
|
|
|
3680
|
if ( is_HashRef($from) ) { |
|
|
50
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
_build_data_serializer($from); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ( is_Str($from) ) { |
106
|
0
|
|
|
|
|
0
|
_build_data_serializer( { serializer => $from, raw => 1 } ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
1673
|
|
|
|
|
49548
|
$from; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_Serializer'; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub to_Digester { |
115
|
884
|
|
|
884
|
0
|
1519
|
my $from = shift; |
116
|
884
|
50
|
|
|
|
2580
|
if ( is_HashRef($from) ) { |
|
|
50
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
_build_digester(%$from); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ( is_Str($from) ) { |
120
|
0
|
|
|
|
|
0
|
_build_digester($from); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
884
|
|
|
|
|
28747
|
$from; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_Digester'; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $data_serializer_loaded = can_load('Data::Serializer'); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _build_data_serializer { |
131
|
0
|
|
|
0
|
|
|
my ($params) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
if ($data_serializer_loaded) { |
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
|
|
|
|
|
|
|
my $digest_loaded = can_load('Digest'); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _build_digester { |
145
|
0
|
0
|
|
0
|
|
|
if ($digest_loaded) { |
146
|
0
|
|
|
|
|
|
return Digest->new(@_); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
0
|
|
|
|
|
|
croak "Digest could not be loaded, cannot handle digester argument"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |