line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pcore::Core::Types; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
31
|
use Pcore; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
1631
|
use Type::Library -base, -declare => qw[ClassNameStr Default FileNameStr PathStr SnakeCaseStr]; |
|
5
|
|
|
|
|
91958
|
|
|
5
|
|
|
|
|
48
|
|
6
|
5
|
|
|
5
|
|
7057
|
use Type::Tiny qw[]; ## no critic qw[Modules::ProhibitEvilModules] |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
97
|
|
7
|
5
|
|
|
5
|
|
2004
|
use Types::Standard qw[:types]; ## no critic qw[Modules::ProhibitEvilModules] |
|
5
|
|
|
|
|
214712
|
|
|
5
|
|
|
|
|
53
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*Type::Tiny::TO_DUMP = sub { |
10
|
0
|
|
|
0
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
return $self->display_name; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
*Type::Tiny::TO_JSON = sub { |
16
|
0
|
|
|
0
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return $self->display_name; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
*Type::Tiny::TO_CBOR = sub { |
22
|
0
|
|
|
0
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return $self->display_name; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*Type::Tiny::FREEZE = sub { |
28
|
0
|
|
|
0
|
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my $serializer = shift; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $self->display_name; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
*Type::Tiny::THAW = sub { |
35
|
0
|
|
|
0
|
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
my $serializer = shift; |
37
|
0
|
|
|
|
|
|
my $data = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
0
|
|
|
|
return eval $data || $data; ## no critic qw[BuiltinFunctions::ProhibitStringyEva] |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$meta->add_type( |
45
|
|
|
|
|
|
|
name => 'ClassNameStr', |
46
|
|
|
|
|
|
|
parent => Str, |
47
|
|
|
|
|
|
|
constraint => sub { |
48
|
|
|
|
|
|
|
return /\A[[:upper:]][[:alnum:]:]+\z/sm ? 1 : 0; |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
inlined => sub { |
51
|
|
|
|
|
|
|
my $constraint = shift; |
52
|
|
|
|
|
|
|
my $varname = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return sprintf '%s && %s =~ /\A[[:upper:]][[:alnum:]:]+\z/sm', $constraint->parent->inline_check($varname), $varname; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
message => sub { |
57
|
|
|
|
|
|
|
return q[Must be a package name string]; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$meta->add_type( |
62
|
|
|
|
|
|
|
name => 'FileNameStr', |
63
|
|
|
|
|
|
|
parent => Str, |
64
|
|
|
|
|
|
|
constraint => sub { |
65
|
|
|
|
|
|
|
return m{\A[^/\\?%*:|"><(){}[\]!#\$\@&\^\$,]+\z}sm ? 1 : 0; |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
inlined => sub { |
68
|
|
|
|
|
|
|
my $constraint = shift; |
69
|
|
|
|
|
|
|
my $varname = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return sprintf '%s && %s =~ m{\A[^/\\?%%*:|"><(){}[\]!#\$\@&\^\$,]+\z}sm', $constraint->parent->inline_check($varname), $varname; |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
message => sub { |
74
|
|
|
|
|
|
|
return q[Must be a valid filename]; |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$meta->add_type( |
79
|
|
|
|
|
|
|
name => 'PathStr', |
80
|
|
|
|
|
|
|
parent => Str, |
81
|
|
|
|
|
|
|
constraint => sub { |
82
|
|
|
|
|
|
|
return /\A[^\\?%*:|"><(){}[\]!#\$\@&\^\$,]+\z/sm ? 1 : 0; |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
inlined => sub { |
85
|
|
|
|
|
|
|
my $constraint = shift; |
86
|
|
|
|
|
|
|
my $varname = shift; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return sprintf '%s && %s =~ /\A[^\\?%%*:|"><(){}[\]!#\$\@&\^\$,]+\z/sm', $constraint->parent->inline_check($varname), $varname; |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
message => sub { |
91
|
|
|
|
|
|
|
return q[Must be a valid path]; |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$meta->add_type( |
96
|
|
|
|
|
|
|
name => 'SnakeCaseStr', |
97
|
|
|
|
|
|
|
parent => Str, |
98
|
|
|
|
|
|
|
constraint => sub { |
99
|
|
|
|
|
|
|
return /\A[^_][[:lower:][:digit:]_]+\z/sm ? 1 : 0; |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
inlined => sub { |
102
|
|
|
|
|
|
|
my $constraint = shift; |
103
|
|
|
|
|
|
|
my $varname = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return sprintf '%s && %s =~ /\A[^_][[:lower:][:digit:]_]+\z/sm', $constraint->parent->inline_check($varname), $varname; |
106
|
|
|
|
|
|
|
}, |
107
|
|
|
|
|
|
|
message => sub { |
108
|
|
|
|
|
|
|
return q[Must be a valid snake_case string]; |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
## -----SOURCE FILTER LOG BEGIN----- |
114
|
|
|
|
|
|
|
## |
115
|
|
|
|
|
|
|
## PerlCritic profile "pcore-script" policy violations: |
116
|
|
|
|
|
|
|
## +------+----------------------+----------------------------------------------------------------------------------------------------------------+ |
117
|
|
|
|
|
|
|
## | Sev. | Lines | Policy | |
118
|
|
|
|
|
|
|
## |======+======================+================================================================================================================| |
119
|
|
|
|
|
|
|
## | 1 | 115, 132 | ValuesAndExpressions::RequireInterpolationOfMetachars - String *may* require interpolation | |
120
|
|
|
|
|
|
|
## +------+----------------------+----------------------------------------------------------------------------------------------------------------+ |
121
|
|
|
|
|
|
|
## |
122
|
|
|
|
|
|
|
## -----SOURCE FILTER LOG END----- |
123
|
|
|
|
|
|
|
__END__ |
124
|
|
|
|
|
|
|
=pod |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=encoding utf8 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Pcore::Core::Types |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DESCRIPTION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |