| 1 | package Mock::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Config (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our %MockConfig; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Mock::Config - temporarily set Config or XSConfig values | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.05 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | XSConfig is readonly, so workaround that. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | use Mock::Config d_fork => 0, perl_patchlevel => ''; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | The importer works only dynamically, not lexically yet. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | use Mock::Config; | ||||||||||||||||||||||||||||
| 29 | Mock::Config->import(startperl => ''); | ||||||||||||||||||||||||||||
| 30 | print $Config{startperl}, ' mocked to empty'; | ||||||||||||||||||||||||||||
| 31 | Mock::Config->unimport; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 SUBROUTINES | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head2 import | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Set pair of Config values, even for the readonly XSConfig implementation, | ||||||||||||||||||||||||||||
| 38 | as used in cperl. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | It does not store the mocked overrides lexically, just dynamically. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub _set { | ||||||||||||||||||||||||||
|
Subroutine
_set: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||
| 45 | 1 | my ($key, $val) = @_; | |||||||||||||||||||||||||||
| 46 | # string context only? | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if (!exists $MockConfig{$key} or $MockConfig{$key} ne $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $MockConfig{$key} or $MockConfig{$key} ne $val
MC/DC0%0/2
not exists $MockConfig{$key} or $MockConfig{$key} ne $val
not exists $MockConfig{$key}
$MockConfig{$key} ne $val
Truth table33%1/3
not(A) or B
A= not exists $MockConfig{$key}B= $MockConfig{$key} ne $val
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if (exists &Config::KEYS) { # compiled XSConfig | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $MockConfig{$key} = $val; # cache new value | |||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 1 | $MockConfig{$key} = tied(%Config::Config)->{$key}; # store the old value | |||||||||||||||||||||||||||
| 52 | 1 | tied(%Config::Config)->{$key} = $val; # set uncompiled Config | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=20.3
| |||||||||||||||||||||||||||||
| 58 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 59 | 2 | ▶ | if (exists &Config::KEYS) { # compiled XSConfig | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | # initialize the mocker | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (!exists &Config_FETCHorig) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | *Config_FETCHorig = \&Config::FETCH; | |||||||||||||||||||||||||||
| 63 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | *Config::FETCH = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($_[0] and exists $MockConfig{$_[1]}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0] and exists $MockConfig{$_[1]}
MC/DC0%0/2
$_[0] and exists $MockConfig{$_[1]}
$_[0]
exists $MockConfig{$_[1]}
Truth table0%0/3
A and B
A= $_[0]B= exists $MockConfig{$_[1]}
| |||||||||||||||||||||||||||||
| 66 | 0 | return $MockConfig{$_[1]}; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | return Config_FETCHorig(@_); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | } | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 2 | ▶ | _set(shift, shift) while @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 unimport | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | This is unstacked and not lexical. | ||||||||||||||||||||||||||||
| 79 | It undoes all imported Config values at once. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 84 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 85 | 1 | ▶ | if (!exists &Config::KEYS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 1 | for (keys %MockConfig) { | |||||||||||||||||||||||||||
| 87 | 1 | tied(%Config::Config)->{$_} = $MockConfig{$_}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 1 | %MockConfig = (); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Reini Urban, C<< <rurban at cpan.org> >> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 BUGS | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Please report any bugs or feature requests at | ||||||||||||||||||||||||||||
| 101 | L<https://github.com/perl11/Mock-Config/issues>. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | We will be notified, and then you'll automatically be notified of | ||||||||||||||||||||||||||||
| 104 | progress on your request as we make changes. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | perldoc Mock::Config | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | You can also look for information at: | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =over 4 | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mock-Config> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | L<http://annocpan.org/dist/Mock-Config> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<http://cpanratings.perl.org/d/Mock-Config> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | L<http://search.cpan.org/dist/Mock-Config/> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =back | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Copyright 2016 cPanel Inc. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 143 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||
| 144 | copy of the full license at: | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||||||
| 149 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||||||
| 150 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||||||
| 151 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||||||
| 154 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||||||
| 155 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||||||
| 158 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||||||
| 161 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||||||
| 162 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||||||
| 163 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||||||
| 164 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||||||
| 165 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||||||
| 166 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||||||
| 167 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||||||
| 170 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||||||
| 171 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||||||
| 172 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||||||
| 173 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||||||
| 174 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||||||
| 175 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||||||
| 176 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 1 | 1; # End of Mock::Config | |||||||||||||||||||||||||||