| 1 | package constant::override; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Sub::Uplevel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use constant; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | my $has_been_called = 0; ## no critic | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub _substituted_import | ||||||||||||||||||||||||||||
| 16 | 200 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_substituted_import: called CC=12 SCAR=24.8
| |||||||||||||||||||||||||||||
| 17 | 200 | my ($original_import, $default_functionality, $substitute, | |||||||||||||||||||||||||||
| 18 | $ignore, $substitute_fn, $class, @args) = @_; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 200 | ▶ | if (not @args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 1 | return; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 199 | my $pkg = caller(1); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 199 | my $multiple = ref $args[0]; | |||||||||||||||||||||||||||
| 27 | 199 | ▶ | if ($multiple and ref $args[0] ne 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$multiple and ref $args[0] ne "HASH"
MC/DC100%2/2
$multiple and ref $args[0] ne "HASH"
$multiple
ref $args[0] ne "HASH"
Truth table100%3/3
A and B
A= $multipleB= ref $args[0] ne "HASH"
| |||||||||||||||||||||||||||||
| 28 | 1 | croak("Invalid reference type '".$multiple."' ". | |||||||||||||||||||||||||||
| 29 | "(must be 'HASH')."); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 198 | my %constants; | |||||||||||||||||||||||||||
| 33 | 198 | ▶ | if ($multiple) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 15 | %constants = %{$args[0]}; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||
| 37 | 183 | $constants{$args[0]} = undef; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 198 | for my $name (keys %constants) { | |||||||||||||||||||||||||||
| 41 | 213 | my $full_name = $pkg.'::'.$name; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 213 | ▶ | if (exists $substitute->{$full_name}) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 44 | 1 | $substitute_fn->($full_name, $substitute->{$full_name}); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | elsif (exists $substitute->{$name}) { | ||||||||||||||||||||||||||||
| 47 | 3 | $substitute_fn->($full_name, $substitute->{$name}); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | elsif (exists $ignore->{$full_name}) { | ||||||||||||||||||||||||||||
| 50 | 1 | next; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | elsif (exists $ignore->{$name}) { | ||||||||||||||||||||||||||||
| 53 | 2 | next; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | elsif ($default_functionality) { | ||||||||||||||||||||||||||||
| 56 | my @values = | ||||||||||||||||||||||||||||
| 57 | ($multiple) | ||||||||||||||||||||||||||||
| 58 | 86 | ▶ | ? $constants{$name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | : @args[1..$#args]; | ||||||||||||||||||||||||||||
| 60 | 86 | $substitute_fn->($full_name, @values); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 120 | uplevel 2, $original_import, ($class, @args); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub import | ||||||||||||||||||||||||||||
| 69 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 70 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 71 | 6 | my %args = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | my ($ignore, $substitute) = @args{qw(ignore substitute)}; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | my %ignore = map { $_ => 1 } @{$args{'ignore'} || []}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{'ignore'} || []
MC/DC100%1/1
$args{'ignore'} || []
$args{'ignore'}
Truth table100%2/2
A
A= $args{'ignore'}
| |||||||||||||||||||||||||||||
| 76 | 6 | ▶ | my %substitute = %{$args{'substitute'} || {}}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{'substitute'} || {}
MC/DC100%1/1
$args{'substitute'} || {}
$args{'substitute'}
Truth table100%2/2
A
A= $args{'substitute'}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 90 | ▶ | my $value_to_fn = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 79 | 90 | my (@values) = @_; | |||||||||||||||||||||||||||
| 80 | (@values == 1) | ||||||||||||||||||||||||||||
| 81 | ? (ref $values[0] eq 'CODE') | ||||||||||||||||||||||||||||
| 82 | ? $values[0] | ||||||||||||||||||||||||||||
| 83 | 56 | ▶ | : sub () { $values[0] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | : sub () { @values } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 6 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 86 | 90 | ▶ | my $substitute_fn = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 90 | my ($binding, @values) = @_; | |||||||||||||||||||||||||||
| 88 | 4 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 4 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 90 | *{$binding} = $value_to_fn->(@values); | |||||||||||||||||||||||||||
| 91 | 6 | }; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 6 | my $default_functionality = (not $has_been_called); | |||||||||||||||||||||||||||
| 94 | 6 | $has_been_called = 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | ## no critic | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 6 | my $original_import = \&{'constant::import'}; | |||||||||||||||||||||||||||
| 102 | 6 | ▶ | *{'constant::import'} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 103 | 200 | _substituted_import($original_import, | |||||||||||||||||||||||||||
| 104 | $default_functionality, | ||||||||||||||||||||||||||||
| 105 | \%substitute, | ||||||||||||||||||||||||||||
| 106 | \%ignore, $substitute_fn, @_) | ||||||||||||||||||||||||||||
| 107 | 6 | }; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 6 | return 1; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 4 | 1; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||||||||