blib/lib/Acme/CPANModules/HidingModules.pm

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