line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# custom type constrants. see Type::Library. |
3
|
|
|
|
|
|
|
# NOTE: can't use Google::RestApi::Setup here because that module imports this one. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use strict; |
6
|
1
|
|
|
1
|
|
385232
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.2'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Types::Standard qw( Undef Str StrMatch Int ArrayRef HashRef Tuple HasMethods ); |
11
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
my @types = qw( |
13
|
|
|
|
|
|
|
ReadableDir ReadableFile |
14
|
|
|
|
|
|
|
EmptyArrayRef EmptyHashRef |
15
|
|
|
|
|
|
|
EmptyString Zero False |
16
|
|
|
|
|
|
|
HasApi |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Type::Library -base, -declare => @types; |
20
|
1
|
|
|
1
|
|
1490
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
21
|
|
|
|
|
|
|
use Exporter; |
22
|
1
|
|
|
1
|
|
278
|
our %EXPORT_TAGS = (all => \@types); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
326
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$meta->add_type( |
28
|
|
|
|
|
|
|
name => 'ReadableDir', |
29
|
|
|
|
|
|
|
parent => Str->where( sub { -d -r; } ), |
30
|
|
|
|
|
|
|
message => sub { "Must point to a file system directory that's readable" }, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$meta->add_type( |
34
|
|
|
|
|
|
|
name => 'ReadableFile', |
35
|
|
|
|
|
|
|
parent => Str->where( sub { -f -r; } ), |
36
|
|
|
|
|
|
|
message => sub { "Must point to a file that's readable" }, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$meta->add_type( |
42
|
|
|
|
|
|
|
name => 'EmptyArrayRef', |
43
|
|
|
|
|
|
|
parent => ArrayRef->where( sub { scalar @$_ == 0; } ), |
44
|
|
|
|
|
|
|
message => sub { "Must be an empty array" }, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$meta->add_type( |
48
|
|
|
|
|
|
|
name => 'EmptyHashRef', |
49
|
|
|
|
|
|
|
parent => HashRef->where( sub { scalar keys %$_ == 0; } ), |
50
|
|
|
|
|
|
|
message => sub { "Must be an empty hash" }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $empty_string = $meta->add_type( |
54
|
|
|
|
|
|
|
name => 'EmptyString', |
55
|
|
|
|
|
|
|
parent => StrMatch[qr/^$/], |
56
|
|
|
|
|
|
|
message => sub { "Must be an empty string" }, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $zero = $meta->add_type( |
60
|
|
|
|
|
|
|
name => 'Zero', |
61
|
|
|
|
|
|
|
parent => Int->where( sub { $_ == 0; } ), |
62
|
|
|
|
|
|
|
message => sub { "Must be an int equal to 0" }, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# TODO: perhaps add emptyarray and emptyhash to this? |
66
|
|
|
|
|
|
|
my $false = $meta->add_type( |
67
|
|
|
|
|
|
|
name => 'False', |
68
|
|
|
|
|
|
|
parent => Undef | $zero | $empty_string, |
69
|
|
|
|
|
|
|
message => sub { "Must evaluate to false" }, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$meta->add_type( |
75
|
|
|
|
|
|
|
name => 'HasApi', |
76
|
|
|
|
|
|
|
parent => HasMethods[qw(api)], |
77
|
|
|
|
|
|
|
message => sub { "Must be an api object"; } |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->make_immutable; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |