/usr/share/perl5/CHI/Types.pm is in libchi-perl 0.60-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | package CHI::Types;
$CHI::Types::VERSION = '0.60';
use Carp;
use CHI::Util qw(can_load parse_duration parse_memory_size);
use MooX::Types::MooseLike qw(exception_message);
use MooX::Types::MooseLike::Base qw(:all);
use MooX::Types::MooseLike::Numeric qw(:all);
use base qw(Exporter);
use strict;
use warnings;
our @EXPORT_OK = ();
our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
MooX::Types::MooseLike::register_types(
[
{
name => 'OnError',
test => sub {
ref( $_[0] ) eq 'CODE' || $_[0] =~ /^(?:ignore|warn|die|log)$/;
},
message => sub {
return exception_message( $_[0], 'a coderef or error level' );
},
inflate => 0,
},
{
name => 'Duration',
subtype_of => PositiveInt,
test => sub { 1 },
message =>
sub { return exception_message( $_[0], 'a positive integer' ) },
inflate => 0,
},
{
name => 'MemorySize',
subtype_of => PositiveInt,
test => sub { 1 },
message =>
sub { return exception_message( $_[0], 'a positive integer' ) },
inflate => 0,
},
{
name => 'DiscardPolicy',
test => sub { !ref( $_[0] ) || ref( $_[0] ) eq 'CODE' },
message => sub {
return exception_message( $_[0], 'a coderef or policy name' );
},
inflate => 0,
},
{
name => 'Serializer',
subtype_of => Object,
test => sub { 1 },
message => sub {
return exception_message( $_[0],
'a serializer, hashref, or string' );
},
inflate => 0,
},
{
name => 'Digester',
subtype_of => Object,
test => sub { 1 },
message => sub {
return exception_message( $_[0],
'a digester, hashref, or string' );
},
inflate => 0,
}
],
__PACKAGE__
);
sub to_MemorySize {
my $from = shift;
if ( is_Num($from) ) {
$from;
}
elsif ( is_Str($from) ) {
parse_memory_size($from);
}
else {
$from;
}
}
push @EXPORT_OK, 'to_MemorySize';
sub to_Duration {
my $from = shift;
if ( is_Str($from) ) {
parse_duration($from);
}
else {
$from;
}
}
push @EXPORT_OK, 'to_Duration';
sub to_Serializer {
my $from = shift;
if ( is_HashRef($from) ) {
_build_data_serializer($from);
}
elsif ( is_Str($from) ) {
_build_data_serializer( { serializer => $from, raw => 1 } );
}
else {
$from;
}
}
push @EXPORT_OK, 'to_Serializer';
sub to_Digester {
my $from = shift;
if ( is_HashRef($from) ) {
_build_digester(%$from);
}
elsif ( is_Str($from) ) {
_build_digester($from);
}
else {
$from;
}
}
push @EXPORT_OK, 'to_Digester';
my $data_serializer_loaded = can_load('Data::Serializer');
sub _build_data_serializer {
my ($params) = @_;
if ($data_serializer_loaded) {
return Data::Serializer->new(%$params);
}
else {
croak
"Could not load Data::Serializer - install Data::Serializer from CPAN to support serializer argument";
}
}
my $digest_loaded = can_load('Digest');
sub _build_digester {
if ($digest_loaded) {
return Digest->new(@_);
}
else {
croak "Digest could not be loaded, cannot handle digester argument";
}
}
1;
|