| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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; | |||||||||||||