« /usr/local/lib/perl5/site_perl/5.44.0/Pod/Coverage/CountParents.pm
↑ Summary
lib/Skilletor/Frontmatter.pm »
| 1 | package namespace::clean; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = '0.27'; | |||||||||||||||||||||||||||
| 7 | 7 | ▶ | $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | our $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use B::Hooks::EndOfScope 'on_scope_end'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # FIXME This is a crock of shit, needs to go away | ||||||||||||||||||||||||||||
| 14 | # currently here to work around https://rt.cpan.org/Ticket/Display.html?id=74151 | ||||||||||||||||||||||||||||
| 15 | # kill with fire when PS::XS is *finally* fixed | ||||||||||||||||||||||||||||
| 16 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 17 | 7 | my $provider; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | if ( "$]" < 5.008007 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | require Package::Stash::PP; | |||||||||||||||||||||||||||
| 21 | 0 | $provider = 'Package::Stash::PP'; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||
| 24 | 7 | require Package::Stash; | |||||||||||||||||||||||||||
| 25 | 7 | $provider = 'Package::Stash'; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 7 | ▶ | eval <<"EOS" or die $@; | ||||||||||||||||||||||||||
|
Subroutine
stash_for: called CC=1 SCAR=0.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub stash_for (\$) { | ||||||||||||||||||||||||||||
| 30 | $provider->new(\$_[0]); | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | EOS | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | use namespace::clean::_Util qw( DEBUGGER_NEEDS_CV_RENAME DEBUGGER_NEEDS_CV_PIVOT ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Built-in debugger CV-retrieval fixups necessary before perl 5.15.5: | ||||||||||||||||||||||||||||
| 41 | # since we are deleting the glob where the subroutine was originally | ||||||||||||||||||||||||||||
| 42 | # defined, the assumptions below no longer hold. | ||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | # In 5.8.9 ~ 5.13.5 (inclusive) the debugger assumes that a CV can | ||||||||||||||||||||||||||||
| 45 | # always be found under sub_fullname($sub) | ||||||||||||||||||||||||||||
| 46 | # Workaround: use sub naming to properly name the sub hidden in the package's | ||||||||||||||||||||||||||||
| 47 | # deleted-stash | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | # In the rest of the range ( ... ~ 5.8.8 and 5.13.6 ~ 5.15.4 ) the debugger | ||||||||||||||||||||||||||||
| 50 | # assumes the name of the glob passed to entersub can be used to find the CV | ||||||||||||||||||||||||||||
| 51 | # Workaround: realias the original glob to the deleted-stash slot | ||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | # While the errors manifest themselves inside perl5db.pl, they are caused by | ||||||||||||||||||||||||||||
| 54 | # problems inside the interpreter. If enabled ($^P & 0x01) and existent, | ||||||||||||||||||||||||||||
| 55 | # the DB::sub sub will be called by the interpreter for any sub call rather | ||||||||||||||||||||||||||||
| 56 | # that call the sub directly. It is provided the real sub to call in $DB::sub, | ||||||||||||||||||||||||||||
| 57 | # but the value given has the issues described above. We only have to enable | ||||||||||||||||||||||||||||
| 58 | # the workaround if DB::sub will be used. | ||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||
| 60 | # Can not tie constants to the current value of $^P directly, | ||||||||||||||||||||||||||||
| 61 | # as the debugger can be enabled during runtime (kinda dubious) | ||||||||||||||||||||||||||||
| 62 | # | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 135 | ▶ | my $RemoveSubs = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 65 | 135 | my $cleanee = shift; | |||||||||||||||||||||||||||
| 66 | 135 | my $store = shift; | |||||||||||||||||||||||||||
| 67 | 135 | my $cleanee_stash = stash_for($cleanee); | |||||||||||||||||||||||||||
| 68 | 135 | my $deleted_stash; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | SYMBOL: | ||||||||||||||||||||||||||||
| 71 | 135 | for my $f (@_) { | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # ignore already removed symbols | ||||||||||||||||||||||||||||
| 74 | 1641 | ▶ | next SYMBOL if $store->{exclude}{ $f }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1641 | ▶ | my $sub = $cleanee_stash->get_symbol("&$f") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | or next SYMBOL; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | my $need_debugger_fixup = | ||||||||||||||||||||||||||||
| 80 | ( DEBUGGER_NEEDS_CV_RENAME or DEBUGGER_NEEDS_CV_PIVOT ) | ||||||||||||||||||||||||||||
| 81 | && | ||||||||||||||||||||||||||||
| 82 | $^P & 0x01 | ||||||||||||||||||||||||||||
| 83 | && | ||||||||||||||||||||||||||||
| 84 | defined &DB::sub | ||||||||||||||||||||||||||||
| 85 | && | ||||||||||||||||||||||||||||
| 86 | 1641 | ref(my $globref = \$cleanee_stash->namespace->{$f}) eq 'GLOB' | |||||||||||||||||||||||||||
| 87 | && | ||||||||||||||||||||||||||||
| 88 | ( $deleted_stash ||= stash_for("namespace::clean::deleted::$cleanee") ) | ||||||||||||||||||||||||||||
| 89 | ; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # convince the Perl debugger to work | ||||||||||||||||||||||||||||
| 92 | # see the comment on top | ||||||||||||||||||||||||||||
| 93 | 1641 | if ( DEBUGGER_NEEDS_CV_RENAME and $need_debugger_fixup ) { | |||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | # Note - both get_subname and set_subname are only compiled when CV_RENAME | ||||||||||||||||||||||||||||
| 96 | # is true ( the 5.8.9 ~ 5.12 range ). On other perls this entire block is | ||||||||||||||||||||||||||||
| 97 | # constant folded away, and so are the definitions in ::_Util | ||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||
| 99 | # Do not be surprised that they are missing without DEBUGGER_NEEDS_CV_RENAME | ||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||
| 101 | namespace::clean::_Util::get_subname( $sub ) eq ( $cleanee_stash->name . "::$f" ) | ||||||||||||||||||||||||||||
| 102 | and | ||||||||||||||||||||||||||||
| 103 | $deleted_stash->add_symbol( | ||||||||||||||||||||||||||||
| 104 | "&$f", | ||||||||||||||||||||||||||||
| 105 | namespace::clean::_Util::set_subname( $deleted_stash->name . "::$f", $sub ), | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | elsif ( DEBUGGER_NEEDS_CV_PIVOT and $need_debugger_fixup ) { | |||||||||||||||||||||||||||
| 109 | $deleted_stash->add_symbol("&$f", $sub); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | my @symbols = map { | ||||||||||||||||||||||||||||
| 113 | 1641 | my $name = $_ . $f; | |||||||||||||||||||||||||||
| 114 | 6564 | my $def = $cleanee_stash->get_symbol($name); | |||||||||||||||||||||||||||
| 115 | 6564 | ▶ | defined($def) ? [$name, $def] : () | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } '$', '@', '%', ''; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1641 | $cleanee_stash->remove_glob($f); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # if this perl needs no renaming trick we need to | ||||||||||||||||||||||||||||
| 121 | # rename the original glob after the fact | ||||||||||||||||||||||||||||
| 122 | DEBUGGER_NEEDS_CV_PIVOT | ||||||||||||||||||||||||||||
| 123 | and | ||||||||||||||||||||||||||||
| 124 | $need_debugger_fixup | ||||||||||||||||||||||||||||
| 125 | and | ||||||||||||||||||||||||||||
| 126 | 1641 | *$globref = $deleted_stash->namespace->{$f}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1641 | $cleanee_stash->add_symbol(@$_) for @symbols; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 7 | }; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub clean_subroutines { | ||||||||||||||||||||||||||
|
Subroutine
clean_subroutines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 0 | my ($nc, $cleanee, @subs) = @_; | |||||||||||||||||||||||||||
| 134 | 0 | $RemoveSubs->($cleanee, {}, @subs); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 135 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=10 SCAR=30.0
| |||||||||||||||||||||||||||||
| 138 | 135 | my ($pragma, @args) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 135 | my (%args, $is_explicit); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | ARG: | ||||||||||||||||||||||||||||
| 143 | 135 | ▶ | while (@args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($args[0] =~ /^\-/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | my $key = shift @args; | |||||||||||||||||||||||||||
| 147 | 0 | my $value = shift @args; | |||||||||||||||||||||||||||
| 148 | 0 | $args{ $key } = $value; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||
| 151 | 0 | $is_explicit++; | |||||||||||||||||||||||||||
| 152 | 0 | last ARG; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 135 | ▶ | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 135 | ▶ | if ($is_explicit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | on_scope_end { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 159 | 0 | $RemoveSubs->($cleanee, {}, @args); | |||||||||||||||||||||||||||
| 160 | 0 | }; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # calling class, all current functions and our storage | ||||||||||||||||||||||||||||
| 165 | 135 | my $functions = $pragma->get_functions($cleanee); | |||||||||||||||||||||||||||
| 166 | 135 | my $store = $pragma->get_class_store($cleanee); | |||||||||||||||||||||||||||
| 167 | 135 | my $stash = stash_for($cleanee); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # except parameter can be array ref or single value | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my %except = map {( $_ => 1 )} ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 171 | $args{ -except } | ||||||||||||||||||||||||||||
| 172 | 0 | ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } ) | |||||||||||||||||||||||||||
| 173 | 135 | : () | |||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # register symbols for removal, if they have a CODE entry | ||||||||||||||||||||||||||||
| 177 | 135 | for my $f (keys %$functions) { | |||||||||||||||||||||||||||
| 178 | 1641 | ▶ | next if $except{ $f }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 1641 | ▶ | next unless $stash->has_symbol("&$f"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 1641 | $store->{remove}{ $f } = 1; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 135 | ▶ | on_scope_end { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 184 | 135 | $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} }); | |||||||||||||||||||||||||||
| 185 | 135 | }; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 135 | return 1; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 192 | 0 | my ($pragma, %args) = @_; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # the calling class, the current functions and our storage | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | my $functions = $pragma->get_functions($cleanee); | |||||||||||||||||||||||||||
| 197 | 0 | my $store = $pragma->get_class_store($cleanee); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # register all unknown previous functions as excluded | ||||||||||||||||||||||||||||
| 200 | 0 | for my $f (keys %$functions) { | |||||||||||||||||||||||||||
| 201 | next if $store->{remove}{ $f } | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | or $store->{exclude}{ $f }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$store->{"remove"}{$f} or $store->{"exclude"}{$f}
MC/DC0%0/2
$store->{"remove"}{$f} or $store->{"exclude"}{$f}
$store->{"remove"}{$f}
$store->{"exclude"}{$f}
Truth table0%0/3
A or B
A= $store->{"remove"}{$f}B= $store->{"exclude"}{$f}
| |||||||||||||||||||||||||||||
| 203 | 0 | $store->{exclude}{ $f } = 1; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | return 1; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 135 | ▶ | sub get_class_store { | ||||||||||||||||||||||||||
|
Subroutine
get_class_store: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | 135 | my ($pragma, $class) = @_; | |||||||||||||||||||||||||||
| 211 | 135 | my $stash = stash_for($class); | |||||||||||||||||||||||||||
| 212 | 135 | my $var = "%$STORAGE_VAR"; | |||||||||||||||||||||||||||
| 213 | 135 | ▶ | $stash->add_symbol($var, {}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | unless $stash->has_symbol($var); | ||||||||||||||||||||||||||||
| 215 | 135 | return $stash->get_symbol($var); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 135 | ▶ | sub get_functions { | ||||||||||||||||||||||||||
|
Subroutine
get_functions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 135 | my ($pragma, $class) = @_; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 135 | my $stash = stash_for($class); | |||||||||||||||||||||||||||
| 222 | return { | ||||||||||||||||||||||||||||
| 223 | 135 | map { $_ => $stash->get_symbol("&$_") } | |||||||||||||||||||||||||||
| 224 | $stash->list_all_symbols('CODE') | ||||||||||||||||||||||||||||
| 225 | }; | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 7 | 'Danger! Laws of Thermodynamics may not apply.' | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||||||||||