| 1 | # Copyright 2010, 2011, 2012, 2015, 2017 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Test-VariousBits. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Test-VariousBits is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # modify it under the terms of the GNU General Public License as published | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # later version. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Test-VariousBits is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Test-VariousBits. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | package Module::Util::Masked; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | require 5; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | $VERSION = 8; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # # Check that Module::Util isn't already loaded. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # # is_valid_module_name() here is a representative func, and not one that's | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # # mangled here (so as not to risk hitting that if something goes badly | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # # wrong). Maybe looking at %INC would be better. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # if (Module::Util->can('is_valid_module_name')) { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # die "Module::Util already loaded, cannot fake after imports may have grabbed its functions"; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use Module::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Crib notes: | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # Module::Util uses File::Find which loads Scalar::Util, so the requires of | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # that here are unnecessary, but included for certainty. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 24 | ▶ | sub _module_is_unplugged { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_module_is_unplugged: called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 24 | my ($module) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 24 | ▶ | if (Devel::Unplug->can('unplugged')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | foreach my $unplugged (Devel::Unplug::unplugged()) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (ref $unplugged ? $module =~ $unplugged : $module eq $unplugged) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 24 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 115 | ▶ | sub _incval_masks_module { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_incval_masks_module: called CC=8 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 115 | my ($incval, $module) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | ### _incval_masks_module() ... | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ### $incval | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ### $module | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 115 | ▶ | ref $incval or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | ▶ | if ($incval == \&Test::Without::Module::fake_module) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | ### incval is Test-Without-Module fake_module ... | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $href = Test::Without::Module::get_forbidden_list(); | |||||||||||||||||||||||||||||||||||||||||
| 73 | ### $href | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Test::Without::Module 0.18 and earlier had Foo::Bar module name | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # Test::Without::Module 0.20 has Foo/Bar.pm path | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # look for either | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (exists $href->{$module} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $href->{$module} or exists $$href{&Module::Util::module_path($module)}
MC/DC0%0/2
exists $href->{$module} or exists $$href{&Module::Util::module_path($module)}
exists $href->{$module}
exists $$href{&Module::Util::module_path($module)}
Truth table0%0/3
A or B
A= exists $href->{$module}B= exists $$href{&Module::Util::module_path($module)}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | || exists $href->{Module::Util::module_path($module)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ### Test-Without-Module masks ... | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 19 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | ▶ | if (Scalar::Util::blessed($incval) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
builtin::blessed($incval) and $incval->isa("Module::Mask") and $incval->is_masked($module)
builtin::blessed($incval) and $incval->isa("Module::Mask")
MC/DC66%2/3
builtin::blessed($incval) and $incval->isa("Module::Mask") and $incval->is_masked($module)
builtin::blessed($incval)
$incval->isa("Module::Mask")
$incval->is_masked($module)
Truth table75%3/4
A and B and C
A= builtin::blessed($incval)B= $incval->isa("Module::Mask")C= $incval->is_masked($module)
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | && $incval->isa('Module::Mask') | ||||||||||||||||||||||||||||||||||||||||||
| 88 | && $incval->is_masked($module)) { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ### Module-Mask masks ... | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | ### not masked ... | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # _pruned_inc($module) using @INC | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # _pruned_inc($module, $dir,$dir,...) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # Return list of dirs preceding any mask of $module. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | ▶ | sub _pruned_inc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pruned_inc: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 14 | ▶ | my @inc = @_ ? @_ : @INC; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | ### _pruned_inc() ... | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 14 | foreach my $pos (0 .. $#inc) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 107 | ▶ | if (_incval_masks_module($inc[$pos],$module)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | $#inc = $pos-1; # truncate | |||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | ▶ | if ($pos == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | $#inc = $pos-1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ### pruned to: @inc | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | return @inc; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my $orig = \&Module::Util::find_installed; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | ▶ | sub Module_Util_Masked__find_installed ($;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Module_Util_Masked__find_installed: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | ### M-U-Masked find_installed(): $module | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | ▶ | if (_module_is_unplugged($module)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | my @inc = _pruned_inc($module, @_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | or return undef; # nothing after pruned | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ### @inc | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | return &$orig($module,@inc); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | *Module::Util::find_installed = \&Module_Util_Masked__find_installed; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | my $orig = \&Module::Util::all_installed; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | sub Module_Util_Masked__all_installed ($;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Module_Util_Masked__all_installed: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | ### M-U-Masked all_installed(): $module | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | ▶ | if (_module_is_unplugged($module)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | ▶ | my @inc = _pruned_inc($module, @_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | or return; # nothing after pruned | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | return &$orig($module,_pruned_inc($module, @_)); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | *Module::Util::all_installed = \&Module_Util_Masked__all_installed; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | my $orig = \&Module::Util::find_in_namespace; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | sub Module_Util_Masked__find_in_namespace ($;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Module_Util_Masked__find_in_namespace: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | my $namespace = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | ### M-U-Masked find_in_namespace(): $namespace | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | my @masks; | |||||||||||||||||||||||||||||||||||||||||
| 165 | my @ret; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ▶ | foreach my $incval (@_ ? @_ : @INC) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 70 | ▶ | if (ref $incval | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $incval and do {
require Scalar::Util;
builtin::refaddr($incval) == \&Test::Without::Module::fake_module or builtin::blessed($incval) and $incval->isa("Module::Mask")
}
MC/DC100%2/2
ref $incval and do {
require Scalar::Util;
builtin::refaddr($incval) == \&Test::Without::Module::fake_module or builtin::blessed($incval) and $incval->isa("Module::Mask")
}
ref $incval
do {
require Scalar::Util;
builtin::refaddr($incval) == \&Test::Without::Module::fake_module or builtin::blessed($incval) and $incval->isa("Module::Mask")
}
Truth table100%3/3
A and B
A= ref $incvalB= do {
require Scalar::Util;
builtin::refaddr($incval) == \&Test::Without::Module::fake_module or builtin::blessed($incval) and $incval->isa("Module::Mask")
}
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | && do { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | ▶ | (Scalar::Util::refaddr($incval) | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
builtin::refaddr($incval) == \&Test::Without::Module::fake_module || builtin::blessed($incval) && $incval->isa('Module::Mask')
builtin::blessed($incval) and $incval->isa("Module::Mask")
MC/DC33%1/3
builtin::refaddr($incval) == \&Test::Without::Module::fake_module || builtin::blessed($incval) && $incval->isa('Module::Mask')
builtin::refaddr($incval) == \&Test::Without::Module::fake_module
builtin::blessed($incval)
$incval->isa("Module::Mask")
Truth table50%2/4
A || B and C
A= builtin::refaddr($incval) == \&Test::Without::Module::fake_moduleB= builtin::blessed($incval)C= $incval->isa("Module::Mask")
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | == \&Test::Without::Module::fake_module | ||||||||||||||||||||||||||||||||||||||||||
| 172 | || (Scalar::Util::blessed($incval) | ||||||||||||||||||||||||||||||||||||||||||
| 173 | && $incval->isa('Module::Mask'))) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | }) { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | push @masks, $incval; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 65 | my @found = &$orig($namespace, $incval); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 65 | @found = grep {! _module_is_unplugged($_)} @found; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 65 | foreach my $mask (@masks) { | |||||||||||||||||||||||||||||||||||||||||
| 180 | 36 | @found = grep {! _incval_masks_module($mask,$_)} @found; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 65 | push @ret, @found; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ### ret inc duplicates: @ret | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 7 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 7 | return grep { !$seen{$_}++ } @ret; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | *Module::Util::find_in_namespace = \&Module_Util_Masked__find_in_namespace; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||||||||||||||||||||||||