line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Bind::maybe; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1097
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
396
|
use Scalar::Util qw(reftype); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
9
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Copied from hiratara's Data::Monad::Maybe |
14
|
|
|
|
|
|
|
sub just { |
15
|
25
|
|
|
25
|
0
|
52
|
my ($self, @values) = @_; |
16
|
25
|
|
|
|
|
309
|
bless [@values], __PACKAGE__; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub nothing { |
20
|
2
|
|
|
2
|
0
|
6
|
my ($self) = @_; |
21
|
2
|
|
|
|
|
8
|
bless \(my $d = undef), __PACKAGE__; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub is_nothing { |
25
|
40
|
|
|
40
|
0
|
79
|
my ($self, $mvar) = @_; |
26
|
40
|
|
|
|
|
134
|
reftype $mvar ne 'ARRAY'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub value { |
30
|
26
|
|
|
26
|
0
|
38
|
my ($self, $mvar) = @_; |
31
|
|
|
|
|
|
|
|
32
|
26
|
100
|
|
|
|
52
|
if ($self->is_nothing($mvar)) { |
33
|
1
|
|
|
|
|
18
|
{}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
25
|
|
|
|
|
445
|
$mvar->[0]; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub unit { |
41
|
15
|
|
|
15
|
0
|
27
|
my ($self, $data) = @_; |
42
|
15
|
|
|
|
|
34
|
$self->just($data); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub bind { |
46
|
|
|
|
|
|
|
my ($self, $mvar, $func) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ($self->is_nothing($mvar)) { |
49
|
|
|
|
|
|
|
return $self->nothing; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $res; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
eval {$res = $func->($self->value($mvar));}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ($@) { |
57
|
|
|
|
|
|
|
return $self->nothing; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if (defined $res) { |
61
|
|
|
|
|
|
|
return $self->just($res); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
|
|
|
|
|
|
return $self->nothing; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub result { |
69
|
13
|
|
|
13
|
0
|
30
|
my ($self, $mvar) = @_; |
70
|
13
|
|
|
|
|
28
|
$self->value($mvar); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Catmandu::Fix::Bind::maybe - a binder that skips fixes if one returns undef or dies |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
do maybe() |
86
|
|
|
|
|
|
|
foo() |
87
|
|
|
|
|
|
|
return_undef() # rest will be ignored |
88
|
|
|
|
|
|
|
bar() |
89
|
|
|
|
|
|
|
end |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
The maybe binder computes all the Fix function and ignores fixes that throw exceptions. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |