| 1 | package Catmandu::Fix::Has; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 107 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 107 | our $VERSION = '1.2025'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 107 | ▶ | use Class::Method::Modifiers qw(install_modifier); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 175 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 175 | my $target = caller; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 107 | ▶ | my $around = do {no strict 'refs'; \&{"${target}::around"}}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 175 | my $fix_args = []; | |||||||||||||||||||||||||||
| 14 | 175 | my $fix_opts = []; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | install_modifier( | ||||||||||||||||||||||||||||
| 17 | $target, 'around', 'has', | ||||||||||||||||||||||||||||
| 18 | 343 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||
| 19 | 343 | my ($orig, $attr, %opts) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | return $orig->($attr, %opts) | ||||||||||||||||||||||||||||
| 22 | 343 | ▶ | unless exists $opts{fix_arg} || exists $opts{fix_opt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $opts{"fix_arg"} or exists $opts{"fix_opt"}
MC/DC100%2/2
exists $opts{"fix_arg"} or exists $opts{"fix_opt"}
exists $opts{"fix_arg"}
exists $opts{"fix_opt"}
Truth table100%3/3
A or B
A= exists $opts{"fix_arg"}B= exists $opts{"fix_opt"}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 323 | ▶ | $opts{is} //= 'ro'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"is"} //= "ro"
MC/DC0%0/1
$opts{"is"} //= "ro"
$opts{"is"}
Truth table50%1/2
A
A= $opts{"is"}
| |||||||||||||||||||||||||||||
| 25 | 323 | ▶ | $opts{init_arg} //= $attr; | ||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"init_arg"} //= $attr
MC/DC0%0/2
$opts{"init_arg"} //= $attr
$opts{"init_arg"}
$attr
Truth table66%2/3
A //= B
A= $opts{"init_arg"}B= $attr
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 323 | my $arg = {key => $opts{init_arg}}; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 323 | ▶ | if ($opts{fix_arg}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 268 | ▶ | $opts{required} //= 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"required"} //= 1
MC/DC0%0/1
$opts{"required"} //= 1
$opts{"required"}
Truth table50%1/2
A
A= $opts{"required"}
| |||||||||||||||||||||||||||||
| 31 | 268 | ▶ | $arg->{collect} = 1 if $opts{fix_arg} eq 'collect'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 268 | push @$fix_args, $arg; | |||||||||||||||||||||||||||
| 33 | 268 | delete $opts{fix_arg}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 323 | ▶ | if ($opts{fix_opt}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 55 | ▶ | $arg->{collect} = 1 if $opts{fix_opt} eq 'collect'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 55 | push @$fix_opts, $arg; | |||||||||||||||||||||||||||
| 39 | 55 | delete $opts{fix_opt}; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 323 | $orig->($attr, %opts); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 175 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | $around->( | ||||||||||||||||||||||||||||
| 47 | 'BUILDARGS', | ||||||||||||||||||||||||||||
| 48 | 678 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 49 | 678 | my $orig = shift; | |||||||||||||||||||||||||||
| 50 | 678 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 678 | ▶ | return $orig->($self, @_) unless @$fix_args || @$fix_opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$fix_args or @$fix_opts
MC/DC0%0/2
@$fix_args or @$fix_opts
@$fix_args
@$fix_opts
Truth table66%2/3
A or B
A= @$fix_argsB= @$fix_opts
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 678 | my $args = {}; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 678 | for my $arg (@$fix_args) { | |||||||||||||||||||||||||||
| 57 | 987 | ▶ | last unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 972 | my $key = $arg->{key}; | |||||||||||||||||||||||||||
| 59 | 972 | ▶ | if ($arg->{collect}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 13 | $args->{$key} = [splice @_, 0, @_]; | |||||||||||||||||||||||||||
| 61 | 13 | last; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 959 | $args->{$key} = shift; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 678 | my $orig_args = $self->$orig(@_); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 678 | for my $arg (@$fix_opts) { | |||||||||||||||||||||||||||
| 69 | 319 | my $key = $arg->{key}; | |||||||||||||||||||||||||||
| 70 | 319 | ▶ | if ($arg->{collect}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 71 | 59 | $args->{$key} = $orig_args; | |||||||||||||||||||||||||||
| 72 | 59 | last; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | elsif (exists $orig_args->{"-$key"}) { | ||||||||||||||||||||||||||||
| 75 | 1 | $args->{$key} = delete $orig_args->{"-$key"}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | elsif (exists $orig_args->{$key}) { | ||||||||||||||||||||||||||||
| 78 | 77 | $args->{$key} = delete $orig_args->{$key}; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 678 | $args; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 175 | ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 107 | 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||