line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unexpected::Types; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
35
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
177
|
|
4
|
4
|
|
|
4
|
|
32
|
use warnings; |
|
4
|
|
|
|
|
68
|
|
|
4
|
|
|
|
|
276
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
62
|
use English qw( -no_match_vars ); |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
43
|
|
7
|
4
|
|
|
4
|
|
2802
|
use Module::Runtime qw( is_module_name require_module ); |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
43
|
|
8
|
4
|
|
|
4
|
|
330
|
use Scalar::Util qw( blessed ); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
371
|
|
9
|
4
|
|
|
|
|
72
|
use Type::Library -base, -declare => |
10
|
|
|
|
|
|
|
qw( LoadableClass NonEmptySimpleStr |
11
|
|
|
|
|
|
|
NonNumericSimpleStr NonZeroPositiveInt |
12
|
|
|
|
|
|
|
NonZeroPositiveNum PositiveInt PositiveNum |
13
|
4
|
|
|
4
|
|
1870
|
RequestFactory SimpleStr Tracer ); |
|
4
|
|
|
|
|
109838
|
|
14
|
4
|
|
|
|
|
61
|
use Type::Utils qw( as coerce extends from |
15
|
4
|
|
|
4
|
|
11942
|
inline_as message subtype via where ); |
|
4
|
|
|
|
|
27550
|
|
16
|
4
|
|
|
4
|
|
7162
|
use Unexpected::Functions qw( inflate_message ); |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
49
|
|
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
|
30
|
BEGIN { extends 'Types::Standard' }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $LOADABLE_CLASS_ERROR; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$Error::TypeTiny::CarpInternal{ 'Method::Generate::Accessor' }++; |
23
|
|
|
|
|
|
|
$Error::TypeTiny::CarpInternal{ 'Method::Generate::Constructor' }++; |
24
|
|
|
|
|
|
|
$Error::TypeTiny::CarpInternal{ 'Sub::Quote' }++; |
25
|
|
|
|
|
|
|
$Error::TypeTiny::CarpInternal{ 'Unexpected::TraitFor::Throwing' }++; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Private functions |
28
|
|
|
|
|
|
|
my $_constraint_for_loadable_class = sub { |
29
|
|
|
|
|
|
|
my $class = shift; is_module_name( $class ) or return 0; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
local $EVAL_ERROR; eval { require_module( $class ) }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$LOADABLE_CLASS_ERROR = $EVAL_ERROR; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return $EVAL_ERROR ? 0 : 1; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $_exception_message_for_object_reference = sub { |
39
|
|
|
|
|
|
|
return inflate_message( 'String [_1] is not an object reference', $_[ 0 ] ); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $_exception_message_for_req_factory = sub { |
43
|
|
|
|
|
|
|
blessed $_[ 0 ] and return inflate_message |
44
|
|
|
|
|
|
|
'Object [_1] is missing the new_from_simple_request method', |
45
|
|
|
|
|
|
|
blessed $_[ 0 ]; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return $_exception_message_for_object_reference->( $_[ 0 ] ); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $_exception_message_for_tracer = sub { |
51
|
|
|
|
|
|
|
blessed $_[ 0 ] and return inflate_message |
52
|
|
|
|
|
|
|
'Object [_1] is missing a frames method', blessed $_[ 0 ]; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $_exception_message_for_object_reference->( $_[ 0 ] ); |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Types |
58
|
|
|
|
|
|
|
subtype NonEmptySimpleStr, as Str, |
59
|
|
|
|
|
|
|
inline_as { |
60
|
|
|
|
|
|
|
$_[ 0 ]->parent->inline_check( $_ ) |
61
|
|
|
|
|
|
|
." and length $_ > 0 and length $_ < 255 and $_ !~ m{ [\\n] }mx" }, |
62
|
|
|
|
|
|
|
message { |
63
|
|
|
|
|
|
|
inflate_message |
64
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a non empty simple string', $_ ) }, |
65
|
|
|
|
|
|
|
where { length $_ > 0 and length $_ < 255 and $_ !~ m{ [\n] }mx }; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
subtype NonZeroPositiveInt, as Int, |
68
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ > 0" }, |
69
|
|
|
|
|
|
|
message { |
70
|
|
|
|
|
|
|
inflate_message |
71
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a non zero positive integer', $_ ) }, |
72
|
|
|
|
|
|
|
where { $_ > 0 }; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
subtype NonZeroPositiveNum, as Num, |
75
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ > 0" }, |
76
|
|
|
|
|
|
|
message { |
77
|
|
|
|
|
|
|
inflate_message |
78
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a non zero positive number', $_ ) }, |
79
|
|
|
|
|
|
|
where { $_ > 0 }; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
subtype PositiveInt, as Int, |
82
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ >= 0" }, |
83
|
|
|
|
|
|
|
message { inflate_message |
84
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a positive integer', $_ ) }, |
85
|
|
|
|
|
|
|
where { $_ >= 0 }; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
subtype PositiveNum, as Num, |
88
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ >= 0" }, |
89
|
|
|
|
|
|
|
message { inflate_message |
90
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a positive number', $_ ) }, |
91
|
|
|
|
|
|
|
where { $_ >= 0 }; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
subtype RequestFactory, as Object, |
94
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ ) |
95
|
|
|
|
|
|
|
." and $_->can( 'new_from_simple_request' )" }, |
96
|
|
|
|
|
|
|
message { $_exception_message_for_req_factory->( $_ ) }, |
97
|
|
|
|
|
|
|
where { $_->can( 'new_from_simple_request' ) }; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
subtype SimpleStr, as Str, |
100
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ ) |
101
|
|
|
|
|
|
|
." and length $_ < 255 and $_ !~ m{ [\\n] }mx" }, |
102
|
|
|
|
|
|
|
message { inflate_message |
103
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a simple string', $_ ) }, |
104
|
|
|
|
|
|
|
where { length $_ < 255 and $_ !~ m{ [\n] }mx }; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
subtype Tracer, as Object, |
107
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_->can( 'frames' )" }, |
108
|
|
|
|
|
|
|
message { $_exception_message_for_tracer->( $_ ) }, |
109
|
|
|
|
|
|
|
where { $_->can( 'frames' ) }; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
subtype LoadableClass, as NonEmptySimpleStr, |
113
|
|
|
|
|
|
|
message { inflate_message( 'String [_1] is not a loadable class: [_2]', |
114
|
|
|
|
|
|
|
$_, $LOADABLE_CLASS_ERROR ) }, |
115
|
|
|
|
|
|
|
where { $_constraint_for_loadable_class->( $_ ) }; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
subtype NonNumericSimpleStr, as SimpleStr, |
118
|
|
|
|
|
|
|
inline_as { $_[ 0 ]->parent->inline_check( $_ )." and $_ !~ m{ \\d+ }mx" }, |
119
|
|
|
|
|
|
|
message { |
120
|
|
|
|
|
|
|
inflate_message |
121
|
|
|
|
|
|
|
( 'Attribute value [_1] is not a non numeric simple string', $_ ) }, |
122
|
|
|
|
|
|
|
where { $_ !~ m{ \d+ }mx }; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |