| 1 | # © 2017-2018 GoodData Corporation | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | package Sub::Params; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '1.0.0'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Hash::Util qw[]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Ref::Util qw[ is_plain_hashref ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our @EXPORT_OK = ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | 'named_or_positional_arguments' | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub named_or_positional_arguments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
named_or_positional_arguments: called CC=11 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my (%args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | my $args = $args{args}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my $names = $args{names}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | return unless $args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | return unless @$args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | return @$args unless @$names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Use restricted hashes to detects how function was called | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | Hash::Util::lock_keys %params, @$names; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # single argument, hashref => can be named argument hashref | ||||||||||||||||||||||||||||||||||||||||||
| 37 | return %params | ||||||||||||||||||||||||||||||||||||||||||
| 38 | if @$args == 1 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | and is_plain_hashref( $args->[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | and eval { %params = %{ $args->[0] }; 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@$args == 1 and is_plain_hashref($args->[0]) and eval {
do {
%params = %{$args->[0];};
1
}
}
@$args == 1 and is_plain_hashref($args->[0])
MC/DC33%1/3
@$args == 1 and is_plain_hashref($args->[0]) and eval {
do {
%params = %{$args->[0];};
1
}
}
@$args == 1
is_plain_hashref($args->[0])
eval {
do {
%params = %{$args->[0];};
1
}
}
Truth table50%2/4
A and B and C
A= @$args == 1B= is_plain_hashref($args->[0])C= eval {
do {
%params = %{$args->[0];};
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # with even number of argument => looks like named arguments | ||||||||||||||||||||||||||||||||||||||||||
| 44 | return %params | ||||||||||||||||||||||||||||||||||||||||||
| 45 | if @$args % 2 == 0 | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | and eval { %params = @$args; 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$args % 2 == 0 and eval {
do {
%params = @$args;
1
}
}
MC/DC100%2/2
@$args % 2 == 0 and eval {
do {
%params = @$args;
1
}
}
@$args % 2 == 0
eval {
do {
%params = @$args;
1
}
}
Truth table100%3/3
A and B
A= @$args % 2 == 0B= eval {
do {
%params = @$args;
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # with more arguments than names should be named arguments | ||||||||||||||||||||||||||||||||||||||||||
| 50 | return %params | ||||||||||||||||||||||||||||||||||||||||||
| 51 | if @$args <= @$names | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | and do { @params{@$names} = @$args; 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$args <= @$names and do {
@params{@$names} = @$args;
1
}
MC/DC0%0/2
@$args <= @$names and do {
@params{@$names} = @$args;
1
}
@$args <= @$names
do {
@params{@$names} = @$args;
1
}
Truth table33%1/3
A and B
A= @$args <= @$namesB= do {
@params{@$names} = @$args;
1
}
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return @$args; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||||||||||||