line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Error::ROP::Imp; |
2
|
5
|
|
|
5
|
|
1641
|
use Moose; |
|
5
|
|
|
|
|
1887729
|
|
|
5
|
|
|
|
|
29
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has value => (is => 'ro', required => 0, default => undef); |
5
|
|
|
|
|
|
|
has failure => (is => 'ro', required => 0, default => ''); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub is_valid { |
8
|
46
|
|
|
46
|
0
|
1049
|
return shift->failure eq ''; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _then_hash { |
12
|
13
|
|
|
13
|
|
25
|
my ($self, @then_clauses) = @_; |
13
|
13
|
|
|
|
|
19
|
my $either = $self; |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
31
|
my $length = @then_clauses / 2; |
16
|
13
|
|
|
|
|
50
|
for(my $i = 0; $i < $length; $i++) { |
17
|
15
|
|
|
|
|
25
|
my $err = $then_clauses[2 * $i]; |
18
|
15
|
|
|
|
|
19
|
my $fn = $then_clauses[2 * $i + 1]; |
19
|
15
|
100
|
|
|
|
28
|
if ($either->is_valid) { |
20
|
12
|
|
|
|
|
220
|
local $_ = $either->value; |
21
|
12
|
|
|
|
|
15
|
my $res = eval { |
22
|
12
|
|
|
|
|
25
|
$fn->($_); |
23
|
|
|
|
|
|
|
}; |
24
|
12
|
100
|
|
|
|
64
|
if ($@) { |
25
|
3
|
100
|
100
|
|
|
13
|
my $msg = length $err > 0 && $err ne 'undef' ? $err : $@; |
26
|
3
|
|
|
|
|
62
|
return Error::ROP::Imp->new(failure => $msg); |
27
|
|
|
|
|
|
|
} |
28
|
9
|
|
|
|
|
166
|
$either = Error::ROP::Imp->new(value => $res); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
10
|
|
|
|
|
61
|
return $either; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _then_list { |
36
|
7
|
|
|
7
|
|
13
|
my ($self, @then_clauses) = @_; |
37
|
7
|
|
|
|
|
8
|
my $either = $self; |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
9
|
my $length = @then_clauses; |
40
|
7
|
|
|
|
|
18
|
for(my $i = 0; $i < $length; $i++) { |
41
|
7
|
|
|
|
|
17
|
my $fn = $then_clauses[$i]; |
42
|
7
|
100
|
|
|
|
12
|
if ($either->is_valid) { |
43
|
3
|
|
|
|
|
55
|
local $_ = $either->value; |
44
|
3
|
|
|
|
|
6
|
my $res = eval { |
45
|
3
|
|
|
|
|
12
|
$fn->($_); |
46
|
|
|
|
|
|
|
}; |
47
|
3
|
100
|
|
|
|
24
|
if ($@) { |
48
|
2
|
|
|
|
|
40
|
return Error::ROP::Imp->new(failure => $@); |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
|
|
|
20
|
$either = Error::ROP::Imp->new(value => $res); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
14
|
return $either; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _wrap_call_with_dollar { |
58
|
0
|
|
|
0
|
|
0
|
my $either = shift; |
59
|
0
|
|
|
|
|
0
|
my $fn = shift; |
60
|
0
|
0
|
|
|
|
0
|
if ($either->is_valid) { |
61
|
0
|
|
|
|
|
0
|
local $_ = $either->value; |
62
|
0
|
|
|
|
|
0
|
my $res = eval { |
63
|
0
|
|
|
|
|
0
|
$fn->($_); |
64
|
|
|
|
|
|
|
}; |
65
|
0
|
0
|
|
|
|
0
|
if ($@) { |
66
|
0
|
|
|
|
|
0
|
return Error::ROP::Imp->new(failure => $@); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
0
|
$either = Error::ROP::Imp->new(value => $res); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub then { |
73
|
20
|
|
|
20
|
0
|
124
|
my ($self, @then_clauses) = @_; |
74
|
|
|
|
|
|
|
|
75
|
20
|
100
|
|
|
|
45
|
if((scalar @then_clauses) % 2 == 0) { |
76
|
13
|
|
|
|
|
29
|
$self->_then_hash(@then_clauses); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
7
|
|
|
|
|
16
|
$self->_then_list(@then_clauses); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
84
|
|
|
|
|
|
|
1; |