line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
25152
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
26
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
package Data::Rx::Type::MooseTC 0.007; |
4
|
|
|
|
|
|
|
# ABSTRACT: experimental / proof of concept Rx types from Moose types |
5
|
1
|
|
|
1
|
|
4
|
use parent 'Data::Rx::CommonType::EasyNew'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4113
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
8
|
1
|
|
|
1
|
|
832
|
use Moose::Util::TypeConstraints (); |
|
1
|
|
|
|
|
244049
|
|
|
1
|
|
|
|
|
200
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
11
|
|
|
|
|
|
|
#pod |
12
|
|
|
|
|
|
|
#pod use Data::Rx; |
13
|
|
|
|
|
|
|
#pod use Data::Rx::Type::MooseTC; |
14
|
|
|
|
|
|
|
#pod use Test::More tests => 2; |
15
|
|
|
|
|
|
|
#pod |
16
|
|
|
|
|
|
|
#pod my $rx = Data::Rx->new({ |
17
|
|
|
|
|
|
|
#pod prefix => { |
18
|
|
|
|
|
|
|
#pod moose => 'tag:rjbs.manxome.org,2008-10-04:rx/moose/', |
19
|
|
|
|
|
|
|
#pod }, |
20
|
|
|
|
|
|
|
#pod type_plugins => [ 'Data::Rx::Type::MooseTC' ] |
21
|
|
|
|
|
|
|
#pod }); |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod my $array_of_int = $rx->make_schema({ |
24
|
|
|
|
|
|
|
#pod type => '/moose/tc', |
25
|
|
|
|
|
|
|
#pod moose_type => 'ArrayRef[Int]', |
26
|
|
|
|
|
|
|
#pod }); |
27
|
|
|
|
|
|
|
#pod |
28
|
|
|
|
|
|
|
#pod ok($array_of_int->check([1]), "[1] is an ArrayRef[Int]"); |
29
|
|
|
|
|
|
|
#pod ok(! $array_of_int->check( 1 ), "1 is not an ArrayRef[Int]"); |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod =head1 WARNING |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod This module is primarly provided as a proof of concept and demonstration of |
34
|
|
|
|
|
|
|
#pod user-written Rx type plugins. It isn't meant to be used for serious work. |
35
|
|
|
|
|
|
|
#pod Moose type constraints may change their interface in the future. |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod =cut |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
0
|
11093
|
sub type_uri { 'tag:rjbs.manxome.org,2008-10-04:rx/moose/tc' } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub guts_from_arg { |
42
|
2
|
|
|
2
|
0
|
540
|
my ($class, $arg) = @_; |
43
|
|
|
|
|
|
|
|
44
|
2
|
50
|
|
|
|
7
|
Carp::croak("no type supplied for $class") unless my $mt = $arg->{moose_type}; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
4
|
my $tc; |
47
|
|
|
|
|
|
|
|
48
|
2
|
50
|
|
|
|
6
|
if (ref $mt) { |
49
|
0
|
|
|
|
|
0
|
$tc = $mt; |
50
|
|
|
|
|
|
|
} else { |
51
|
|
|
|
|
|
|
package |
52
|
|
|
|
|
|
|
Moose::Util::TypeConstraints; # SUCH LONG IDENTIFIERS |
53
|
2
|
|
|
|
|
8
|
$tc = find_or_parse_type_constraint( normalize_type_constraint_name($mt) ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
2
|
50
|
|
|
|
4654
|
Carp::croak("could not make Moose type constraint from $mt") |
57
|
|
|
|
|
|
|
unless $tc->isa('Moose::Meta::TypeConstraint'); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
7
|
return { tc => $tc }; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub assert_valid { |
63
|
3
|
|
|
3
|
0
|
622
|
my ($self, $value) = @_; |
64
|
|
|
|
|
|
|
|
65
|
3
|
100
|
|
|
|
15
|
unless ($self->{tc}->check($value)) { |
66
|
1
|
|
|
|
|
73
|
$self->fail({ |
67
|
|
|
|
|
|
|
error => [ qw(type) ], |
68
|
|
|
|
|
|
|
message => "found value does not pass type constraint", |
69
|
|
|
|
|
|
|
value => $value, |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
147
|
return 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=pod |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=encoding UTF-8 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Data::Rx::Type::MooseTC - experimental / proof of concept Rx types from Moose types |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 VERSION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
version 0.007 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SYNOPSIS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
use Data::Rx; |
95
|
|
|
|
|
|
|
use Data::Rx::Type::MooseTC; |
96
|
|
|
|
|
|
|
use Test::More tests => 2; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $rx = Data::Rx->new({ |
99
|
|
|
|
|
|
|
prefix => { |
100
|
|
|
|
|
|
|
moose => 'tag:rjbs.manxome.org,2008-10-04:rx/moose/', |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
type_plugins => [ 'Data::Rx::Type::MooseTC' ] |
103
|
|
|
|
|
|
|
}); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $array_of_int = $rx->make_schema({ |
106
|
|
|
|
|
|
|
type => '/moose/tc', |
107
|
|
|
|
|
|
|
moose_type => 'ArrayRef[Int]', |
108
|
|
|
|
|
|
|
}); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
ok($array_of_int->check([1]), "[1] is an ArrayRef[Int]"); |
111
|
|
|
|
|
|
|
ok(! $array_of_int->check( 1 ), "1 is not an ArrayRef[Int]"); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 PERL VERSION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This library should run on perls released even a long time ago. It should work |
116
|
|
|
|
|
|
|
on any version of perl released in the last five years. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Although it may work on older versions of perl, no guarantee is made that the |
119
|
|
|
|
|
|
|
minimum required version will not be increased. The version may be increased |
120
|
|
|
|
|
|
|
for any reason, and there is no promise that patches will be accepted to lower |
121
|
|
|
|
|
|
|
the minimum required perl. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 WARNING |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This module is primarly provided as a proof of concept and demonstration of |
126
|
|
|
|
|
|
|
user-written Rx type plugins. It isn't meant to be used for serious work. |
127
|
|
|
|
|
|
|
Moose type constraints may change their interface in the future. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@semiotic.systems> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Ricardo SIGNES. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
138
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |