line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::Types; |
2
|
|
|
|
|
|
|
$CHI::Types::VERSION = '0.61'; |
3
|
20
|
|
|
20
|
|
142
|
use Carp; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
1467
|
|
4
|
20
|
|
|
20
|
|
124
|
use CHI::Util qw(can_load parse_duration parse_memory_size); |
|
20
|
|
|
|
|
39
|
|
|
20
|
|
|
|
|
1087
|
|
5
|
20
|
|
|
20
|
|
140
|
use MooX::Types::MooseLike qw(exception_message); |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
825
|
|
6
|
20
|
|
|
20
|
|
135
|
use MooX::Types::MooseLike::Base qw(:all); |
|
20
|
|
|
|
|
37
|
|
|
20
|
|
|
|
|
7215
|
|
7
|
20
|
|
|
20
|
|
9920
|
use MooX::Types::MooseLike::Numeric qw(:all); |
|
20
|
|
|
|
|
29878
|
|
|
20
|
|
|
|
|
3694
|
|
8
|
20
|
|
|
20
|
|
178
|
use base qw(Exporter); |
|
20
|
|
|
|
|
58
|
|
|
20
|
|
|
|
|
2773
|
|
9
|
20
|
|
|
20
|
|
159
|
use strict; |
|
20
|
|
|
|
|
36
|
|
|
20
|
|
|
|
|
491
|
|
10
|
20
|
|
|
20
|
|
116
|
use warnings; |
|
20
|
|
|
|
|
40
|
|
|
20
|
|
|
|
|
17849
|
|
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
|
111
|
|
|
111
|
0
|
5370
|
my $from = shift; |
77
|
111
|
100
|
|
|
|
344
|
if ( is_Num($from) ) { |
|
|
50
|
|
|
|
|
|
78
|
104
|
|
|
|
|
2641
|
$from; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ( is_Str($from) ) { |
81
|
7
|
|
|
|
|
192
|
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
|
26
|
|
|
26
|
0
|
539
|
my $from = shift; |
91
|
26
|
50
|
|
|
|
103
|
if ( is_Str($from) ) { |
92
|
26
|
|
|
|
|
327
|
parse_duration($from); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
|
|
|
|
0
|
$from; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_Duration'; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub to_Serializer { |
101
|
1905
|
|
|
1905
|
0
|
9284
|
my $from = shift; |
102
|
1905
|
50
|
|
|
|
4205
|
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
|
1905
|
|
|
|
|
50952
|
$from; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
push @EXPORT_OK, 'to_Serializer'; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub to_Digester { |
115
|
1000
|
|
|
1000
|
0
|
2042
|
my $from = shift; |
116
|
1000
|
50
|
|
|
|
3076
|
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
|
1000
|
|
|
|
|
30667
|
$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; |