Catmandu/Fix/Bind/maybe.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 86.3% 57 / 66 CC 5 SCAR 6.6
CC
5
Cov
96%
bind
4.0
value
2.0
BEGIN
1.0
CRAP 1.9
« Catmandu/Fix/Bind/importer.pm ↑ Summary Catmandu/Importer/CSV.pm »
1 package Catmandu::Fix::Bind::maybe;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.2025';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Catmandu::Fix::Bind';
12  
13 # Copied from hiratara's Data::Monad::Maybe
14 25 ▶sub just {
Subroutine just: called CC=1 SCAR=0.0
Pod undocumented
15 25 my ($self, @values) = @_;
16 25 bless [@values], __PACKAGE__;
17 }
18  
19 2 ▶sub nothing {
Subroutine nothing: called CC=1 SCAR=0.0
Pod undocumented
20 2 my ($self) = @_;
21 2 bless \(my $d = undef), __PACKAGE__;
22 }
23  
24 40 ▶sub is_nothing {
Subroutine is_nothing: called CC=1 SCAR=0.0
Pod undocumented
25 40 my ($self, $mvar) = @_;
26 40 reftype $mvar ne 'ARRAY';
27 }
28  
29 26 ▶sub value {
Subroutine value: called CC=2 SCAR=6.9
Pod undocumented
30 26 my ($self, $mvar) = @_;
31  
32 26 ▶ if ($self->is_nothing($mvar)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_nothing($mvar)) { } 1 25 26
33 1 {};
34 }
35 else {
36 25 $mvar->[0];
37 }
38 }
39  
40 15 ▶sub unit {
Subroutine unit: called CC=1 SCAR=0.0
Pod undocumented
41 15 my ($self, $data) = @_;
42 15 $self->just($data);
43 }
44  
45 14 ▶sub bind {
Subroutine bind: called CC=4 SCAR=13.9
Pod undocumented
46 14 my ($self, $mvar, $func) = @_;
47  
48 14 ▶ if ($self->is_nothing($mvar)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_nothing($mvar)) 1 13 14
49 1 return $self->nothing;
50 }
51  
52 13 my $res;
53  
54 13 eval {$res = $func->($self->value($mvar));};
55  
56 11 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 11 11
57 0 return $self->nothing;
58 }
59  
60 11 ▶ if (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res) { } 10 1 11
61 10 return $self->just($res);
62 }
63 else {
64 1 return $self->nothing;
65 }
66 }
67  
68 13 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod undocumented
69 13 my ($self, $mvar) = @_;
70 13 $self->value($mvar);
71 }
72  
73 1 1;
74  
75 __END__
« Catmandu/Fix/Bind/importer.pm ↑ Summary Catmandu/Importer/CSV.pm »