| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::CPANModules::HidingModules; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
268659
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
379
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
6
|
|
|
|
|
|
|
our $DATE = '2023-10-29'; # DATE |
|
7
|
|
|
|
|
|
|
our $DIST = 'Acme-CPANModules-HidingModules'; # DIST |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.005'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $text = <<'_'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
So you want to convince some Perl code that some modules that are actually |
|
13
|
|
|
|
|
|
|
installed, aren't? There are several ways to accomplish this, with different |
|
14
|
|
|
|
|
|
|
effects and levels of convincing. This list details them. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
**Why?** |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
First of all, why would you want to do this? Almost always, the answer is: for |
|
19
|
|
|
|
|
|
|
testing purposes. For example, you want to make sure that your code can work |
|
20
|
|
|
|
|
|
|
without an optional module. Or, alternatively, you want to test how your code |
|
21
|
|
|
|
|
|
|
fails under the absence of certain modules. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
**Making modules not loadable** |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Most of the time, you just want to make certain modules not loadable. That is, |
|
27
|
|
|
|
|
|
|
making `require SomeModule` or `use Module` fail. To do this, you usually |
|
28
|
|
|
|
|
|
|
install a hook at the first element of `@INC`. The hook would die when it |
|
29
|
|
|
|
|
|
|
receives a request to load a module that you want to hide. Some tools that work |
|
30
|
|
|
|
|
|
|
this way include: |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
family, including its thin wrapper . |
|
33
|
|
|
|
|
|
|
lib::filter et al supports hiding modules that you specify, as well as hiding |
|
34
|
|
|
|
|
|
|
all core modules or all non-core modules. They also support recursive allowing, |
|
35
|
|
|
|
|
|
|
i.e. you want to allow Moo and all the modules that Moo loads, and all the |
|
36
|
|
|
|
|
|
|
modules that they load, and so on. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
. Devel::Hide also works by installing a hook in `@INC`. It |
|
39
|
|
|
|
|
|
|
supports propagating the hiding to child process by setting PERL5OPT environment |
|
40
|
|
|
|
|
|
|
variable. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
**Fooling module path finders** |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Depending on which tool you use to find a module's path, here are some patches |
|
48
|
|
|
|
|
|
|
you can load to fool the finder. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
**Fooling module listers** |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Depending on which tool you use to find a module's path, here are some patches |
|
58
|
|
|
|
|
|
|
you can load to fool the lister tool. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
**Hard-core hiding** |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
To fool code that tries to find the module files themselves without using any |
|
72
|
|
|
|
|
|
|
module, i.e. by iterating @INC, you will need to actually (temporarily) rename |
|
73
|
|
|
|
|
|
|
the module files. and does this. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
_ |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
our $LIST = { |
|
78
|
|
|
|
|
|
|
summary => 'List of modules to hide other modules', |
|
79
|
|
|
|
|
|
|
description => $text, |
|
80
|
|
|
|
|
|
|
tags => ['task'], |
|
81
|
|
|
|
|
|
|
entries => [ |
|
82
|
|
|
|
|
|
|
map { +{module=>$_} } |
|
83
|
|
|
|
|
|
|
do { my %seen; grep { !$seen{$_}++ } |
|
84
|
|
|
|
|
|
|
($text =~ //g) |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
], |
|
87
|
|
|
|
|
|
|
}; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
# ABSTRACT: List of modules to hide other modules |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |