| 1 | package Catmandu::Fix::Bind::with; | ||||||||||||||
| 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 Clone (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Catmandu::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Catmandu::Fix::Has; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 1 | with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | has path => (fix_opt => 1); | |||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | ▶ | sub zero { | ||||||||||||
|
Subroutine
zero: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 18 | 0 | my ($self) = @_; | |||||||||||||
| 19 | 0 | []; | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 12 | ▶ | sub unit { | ||||||||||||
|
Subroutine
unit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 23 | 12 | my ($self, $data) = @_; | |||||||||||||
| 24 | 12 | ▶ | defined $self->path ? Catmandu::Util::data_at($self->path, $data) : $data; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 12 | ▶ | sub bind { | ||||||||||||
|
Subroutine
bind: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||
| 28 | 12 | my ($self, $mvar, $code) = @_; | |||||||||||||
| 29 | |||||||||||||||
| 30 | 12 | ▶ | if (Catmandu::Util::is_hash_ref($mvar)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 31 | 10 | my $copy = Clone::clone($mvar); | |||||||||||||
| 32 | |||||||||||||||
| 33 | 10 | $copy = $code->($copy); | |||||||||||||
| 34 | |||||||||||||||
| 35 | 10 | ▶ | if (ref($copy) eq 'reject') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | #map { delete $mvar->{$_} } (keys %$mvar); | ||||||||||||||
| 38 | 1 | %$mvar = (); | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | else { | ||||||||||||||
| 41 | 9 | %$mvar = %$copy; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 10 | return $mvar; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | elsif (Catmandu::Util::is_array_ref($mvar)) { | ||||||||||||||
| 47 | 2 | my $idx = 0; | |||||||||||||
| 48 | 2 | for my $item (@$mvar) { | |||||||||||||
| 49 | 5 | $item = $code->($item); | |||||||||||||
| 50 | |||||||||||||||
| 51 | 5 | ▶ | if (ref($item) eq 'reject') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 1 | splice(@$mvar, $idx, 1); | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 5 | $idx++; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 2 | return $mvar; | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | else { | ||||||||||||||
| 60 | 0 | return $self->zero; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 2 | ▶ | sub reject { | ||||||||||||
|
Subroutine
reject: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||
| 65 | 2 | my ($self, $var) = @_; | |||||||||||||
| 66 | 2 | ▶ | return bless $var, 'reject' if ref($var); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | return bless \$var, 'reject'; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 1 | 1; | |||||||||||||
| 71 | |||||||||||||||
| 72 | __END__ | ||||||||||||||