line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
720
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
3
|
|
|
|
|
|
|
package Data::Rx::CommonType; |
4
|
|
|
|
|
|
|
# ABSTRACT: base class for core Rx types |
5
|
|
|
|
|
|
|
$Data::Rx::CommonType::VERSION = '0.200006'; |
6
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
5
|
use Scalar::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
8
|
1
|
|
|
1
|
|
616
|
use Data::Rx::Failure; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
804
|
use Data::Rx::FailureSet; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
639
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# requires: new_checker, type, type_uri, rx, assert_valid |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
0
|
0
|
sub new_checker { Carp::croak "$_[0] did not implement new_checker" } |
14
|
0
|
|
|
0
|
0
|
0
|
sub type_uri { Carp::croak "$_[0] did not implement type_uri" } |
15
|
0
|
|
|
0
|
0
|
0
|
sub type { Carp::croak "$_[0] did not implement type" } |
16
|
0
|
|
|
0
|
0
|
0
|
sub rx { Carp::croak "$_[0] did not implement rx" } |
17
|
0
|
|
|
0
|
0
|
0
|
sub assert_valid { Carp::croak "$_[0] did not implement assert_valid" } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub check { |
20
|
0
|
|
|
0
|
0
|
0
|
my ($self, $value) = @_; |
21
|
0
|
|
|
|
|
0
|
local $@; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
0
|
return 1 if eval { $self->assert_valid($value); }; |
|
0
|
|
|
|
|
0
|
|
24
|
0
|
|
|
|
|
0
|
my $error = $@; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# If you wanted the failure, you should've used assert_valid. |
27
|
0
|
0
|
|
|
|
0
|
return 0 if eval { $error->isa('Data::Rx::FailureSet') }; |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
die $error; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new_fail { |
33
|
1507
|
|
|
1507
|
0
|
2571
|
my ($self, $struct) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1507
|
|
33
|
|
|
9613
|
$struct->{type} ||= $self->type; |
36
|
|
|
|
|
|
|
|
37
|
1507
|
|
|
|
|
6055
|
Data::Rx::FailureSet->new({ |
38
|
|
|
|
|
|
|
rx => $self->rx, |
39
|
|
|
|
|
|
|
failures => [ |
40
|
|
|
|
|
|
|
Data::Rx::Failure->new({ |
41
|
|
|
|
|
|
|
rx => $self->rx, |
42
|
|
|
|
|
|
|
struct => $struct, |
43
|
|
|
|
|
|
|
}) |
44
|
|
|
|
|
|
|
] |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub fail { |
49
|
1460
|
|
|
1460
|
0
|
3048
|
my ($self, $struct) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1460
|
|
|
|
|
4966
|
die $self->new_fail($struct); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub perform_subchecks { |
55
|
193
|
|
|
193
|
0
|
655
|
my ($self, $subchecks) = @_; |
56
|
|
|
|
|
|
|
|
57
|
193
|
|
|
|
|
317
|
my @fails; |
58
|
|
|
|
|
|
|
|
59
|
193
|
|
|
|
|
380
|
foreach my $subcheck (@$subchecks) { |
60
|
421
|
100
|
|
|
|
1174
|
if (Scalar::Util::blessed($subcheck)) { |
61
|
47
|
|
|
|
|
88
|
push @fails, $subcheck; |
62
|
47
|
|
|
|
|
107
|
next; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
374
|
|
|
|
|
635
|
my ($value, $checker, $context) = @$subcheck; |
66
|
|
|
|
|
|
|
|
67
|
374
|
100
|
|
|
|
525
|
next if eval { $checker->assert_valid($value) }; |
|
374
|
|
|
|
|
1174
|
|
68
|
|
|
|
|
|
|
|
69
|
148
|
|
|
|
|
534
|
my $failure = $@; |
70
|
|
|
|
|
|
|
Carp::confess($failure) |
71
|
148
|
50
|
|
|
|
744
|
unless eval { $failure->isa('Data::Rx::FailureSet') || |
|
148
|
50
|
|
|
|
773
|
|
72
|
|
|
|
|
|
|
$failure->isa('Data::Rx::Failure') }; |
73
|
|
|
|
|
|
|
|
74
|
148
|
|
|
|
|
477
|
$failure->contextualize({ |
75
|
|
|
|
|
|
|
type => $self->type, |
76
|
|
|
|
|
|
|
%$context, |
77
|
|
|
|
|
|
|
}); |
78
|
|
|
|
|
|
|
|
79
|
148
|
|
|
|
|
476
|
push @fails, $failure; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
193
|
100
|
|
|
|
535
|
if (@fails) { |
83
|
125
|
|
|
|
|
495
|
die Data::Rx::FailureSet->new( { rx => $self->rx, failures => \@fails } ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
68
|
|
|
|
|
179
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |