| Filename | /home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm |
| Statements | Executed 11531 statements in 291ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 54 | 2 | 1 | 136ms | 294ms | namespace::clean::__ANON__[:59] |
| 5 | 5 | 5 | 3.33ms | 11.3ms | namespace::clean::import |
| 49 | 1 | 1 | 2.26ms | 265ms | namespace::clean::clean_subroutines |
| 1 | 1 | 1 | 1.89ms | 3.19ms | namespace::clean::BEGIN@15 |
| 1 | 1 | 1 | 1.76ms | 9.36ms | namespace::clean::BEGIN@17 |
| 5 | 1 | 1 | 1.41ms | 3.97ms | namespace::clean::get_functions |
| 5 | 1 | 1 | 388µs | 916µs | namespace::clean::get_class_store |
| 5 | 1 | 1 | 190µs | 31.8ms | namespace::clean::__ANON__[:117] |
| 1 | 1 | 1 | 83µs | 379µs | namespace::clean::BEGIN@14 |
| 1 | 1 | 1 | 69µs | 151µs | namespace::clean::BEGIN@16 |
| 1 | 1 | 1 | 56µs | 132µs | namespace::clean::BEGIN@166 |
| 1 | 1 | 1 | 52µs | 52µs | namespace::clean::BEGIN@2 |
| 4 | 1 | 1 | 39µs | 39µs | namespace::clean::CORE:match (opcode) |
| 1 | 1 | 1 | 39µs | 111µs | namespace::clean::BEGIN@10 |
| 1 | 1 | 1 | 38µs | 53µs | namespace::clean::BEGIN@11 |
| 1 | 1 | 1 | 34µs | 149µs | namespace::clean::BEGIN@13 |
| 1 | 1 | 1 | 17µs | 17µs | namespace::clean::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | namespace::clean::__ANON__[:90] |
| 0 | 0 | 0 | 0s | 0s | namespace::clean::unimport |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package namespace::clean; | ||||
| 2 | # spent 52µs within namespace::clean::BEGIN@2 which was called:
# once (52µs+0s) by MooseX::Types::Base::BEGIN@16 at line 4 | ||||
| 3 | 1 | 31µs | $namespace::clean::AUTHORITY = 'cpan:PHAYLON'; | ||
| 4 | 1 | 89µs | 1 | 52µs | } # spent 52µs making 1 call to namespace::clean::BEGIN@2 |
| 5 | # spent 17µs within namespace::clean::BEGIN@5 which was called:
# once (17µs+0s) by MooseX::Types::Base::BEGIN@16 at line 7 | ||||
| 6 | 1 | 20µs | $namespace::clean::VERSION = '0.18'; | ||
| 7 | 1 | 70µs | 1 | 17µs | } # spent 17µs making 1 call to namespace::clean::BEGIN@5 |
| 8 | # ABSTRACT: Keep imports and functions out of your namespace | ||||
| 9 | |||||
| 10 | 3 | 96µs | 2 | 184µs | # spent 111µs (39+72) within namespace::clean::BEGIN@10 which was called:
# once (39µs+72µs) by MooseX::Types::Base::BEGIN@16 at line 10 # spent 111µs making 1 call to namespace::clean::BEGIN@10
# spent 72µs making 1 call to warnings::import |
| 11 | 3 | 101µs | 2 | 68µs | # spent 53µs (38+15) within namespace::clean::BEGIN@11 which was called:
# once (38µs+15µs) by MooseX::Types::Base::BEGIN@16 at line 11 # spent 53µs making 1 call to namespace::clean::BEGIN@11
# spent 15µs making 1 call to strict::import |
| 12 | |||||
| 13 | 3 | 128µs | 2 | 264µs | # spent 149µs (34+115) within namespace::clean::BEGIN@13 which was called:
# once (34µs+115µs) by MooseX::Types::Base::BEGIN@16 at line 13 # spent 149µs making 1 call to namespace::clean::BEGIN@13
# spent 115µs making 1 call to vars::import |
| 14 | 3 | 305µs | 3 | 675µs | # spent 379µs (83+296) within namespace::clean::BEGIN@14 which was called:
# once (83µs+296µs) by MooseX::Types::Base::BEGIN@16 at line 14 # spent 379µs making 1 call to namespace::clean::BEGIN@14
# spent 169µs making 1 call to Exporter::import
# spent 127µs making 1 call to UNIVERSAL::VERSION |
| 15 | 3 | 752µs | 3 | 3.51ms | # spent 3.19ms (1.89+1.31) within namespace::clean::BEGIN@15 which was called:
# once (1.89ms+1.31ms) by MooseX::Types::Base::BEGIN@16 at line 15 # spent 3.19ms making 1 call to namespace::clean::BEGIN@15
# spent 239µs making 1 call to Exporter::import
# spent 73µs making 1 call to UNIVERSAL::VERSION |
| 16 | 3 | 185µs | 3 | 233µs | # spent 151µs (69+82) within namespace::clean::BEGIN@16 which was called:
# once (69µs+82µs) by MooseX::Types::Base::BEGIN@16 at line 16 # spent 151µs making 1 call to namespace::clean::BEGIN@16
# spent 50µs making 1 call to UNIVERSAL::VERSION
# spent 32µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
| 17 | 3 | 3.45ms | 3 | 10.6ms | # spent 9.36ms (1.76+7.60) within namespace::clean::BEGIN@17 which was called:
# once (1.76ms+7.60ms) by MooseX::Types::Base::BEGIN@16 at line 17 # spent 9.36ms making 1 call to namespace::clean::BEGIN@17
# spent 1.19ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
# spent 56µs making 1 call to UNIVERSAL::VERSION |
| 18 | |||||
| 19 | 1 | 4µs | $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; | ||
| 20 | |||||
| 21 | |||||
| 22 | # spent 294ms (136+159) within namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:59] which was called 54 times, avg 5.45ms/call:
# 49 times (121ms+142ms) by namespace::clean::clean_subroutines at line 63, avg 5.36ms/call
# 5 times (14.7ms+16.9ms) by namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:117] at line 116, avg 6.31ms/call | ||||
| 23 | |||||
| 24 | 54 | 234µs | my $cleanee = shift; | ||
| 25 | 54 | 172µs | my $store = shift; | ||
| 26 | 54 | 1.95ms | 54 | 924µs | my $cleanee_stash = Package::Stash->new($cleanee); # spent 924µs making 54 calls to Package::Stash::XS::new, avg 17µs/call |
| 27 | 54 | 2.35ms | 54 | 1.40ms | my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee"); # spent 1.40ms making 54 calls to Package::Stash::XS::new, avg 26µs/call |
| 28 | SYMBOL: | ||||
| 29 | 54 | 1.28ms | for my $f (@_) { | ||
| 30 | 825 | 2.68ms | my $variable = "&$f"; | ||
| 31 | # ignore already removed symbols | ||||
| 32 | 825 | 2.80ms | next SYMBOL if $store->{exclude}{ $f }; | ||
| 33 | |||||
| 34 | 825 | 28.6ms | 1650 | 23.1ms | next SYMBOL unless $cleanee_stash->has_symbol($variable); # spent 19.5ms making 825 calls to Package::Stash::XS::has_symbol, avg 24µs/call
# spent 3.64ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call |
| 35 | |||||
| 36 | 825 | 18.0ms | 825 | 4.10ms | if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') { # spent 4.10ms making 825 calls to Package::Stash::XS::namespace, avg 5µs/call |
| 37 | # convince the Perl debugger to work | ||||
| 38 | # it assumes that sub_fullname($sub) can always be used to find the CV again | ||||
| 39 | # since we are deleting the glob where the subroutine was originally | ||||
| 40 | # defined, that assumption no longer holds, so we need to move it | ||||
| 41 | # elsewhere and point the CV's name to the new glob. | ||||
| 42 | 825 | 27.2ms | 1650 | 21.5ms | my $sub = $cleanee_stash->get_symbol($variable); # spent 18.0ms making 825 calls to Package::Stash::XS::get_symbol, avg 22µs/call
# spent 3.49ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call |
| 43 | 825 | 21.8ms | 1650 | 24.1ms | if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) { # spent 19.9ms making 825 calls to Sub::Identify::sub_fullname, avg 24µs/call
# spent 4.17ms making 825 calls to Package::Stash::XS::name, avg 5µs/call |
| 44 | my $new_fq = $deleted_stash->name . "::$f"; | ||||
| 45 | subname($new_fq, $sub); | ||||
| 46 | $deleted_stash->add_symbol($variable, $sub); | ||||
| 47 | } | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | my ($scalar, $array, $hash, $io) = map { | ||||
| 51 | 825 | 105ms | 6600 | 81.6ms | $cleanee_stash->get_symbol($_ . $f) # spent 67.7ms making 3300 calls to Package::Stash::XS::get_symbol, avg 21µs/call
# spent 13.9ms making 3300 calls to Package::Stash::XS::namespace, avg 4µs/call |
| 52 | } '$', '@', '%', ''; | ||||
| 53 | 825 | 31.9ms | 1650 | 26.2ms | $cleanee_stash->remove_glob($f); # spent 22.9ms making 825 calls to Package::Stash::XS::remove_glob, avg 28µs/call
# spent 3.30ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call |
| 54 | 825 | 21.6ms | for my $var (['$', $scalar], ['@', $array], ['%', $hash], ['', $io]) { | ||
| 55 | 3300 | 7.21ms | next unless defined $var->[1]; | ||
| 56 | $cleanee_stash->add_symbol($var->[0] . $f, $var->[1]); | ||||
| 57 | } | ||||
| 58 | } | ||||
| 59 | 1 | 18µs | }; | ||
| 60 | |||||
| 61 | # spent 265ms (2.26+263) within namespace::clean::clean_subroutines which was called 49 times, avg 5.41ms/call:
# 49 times (2.26ms+263ms) by namespace::autoclean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/autoclean.pm:57] at line 56 of namespace/autoclean.pm, avg 5.41ms/call | ||||
| 62 | 49 | 816µs | my ($nc, $cleanee, @subs) = @_; | ||
| 63 | 49 | 1.35ms | 49 | 263ms | $RemoveSubs->($cleanee, {}, @subs); # spent 263ms making 49 calls to namespace::clean::__ANON__[namespace/clean.pm:59], avg 5.36ms/call |
| 64 | } | ||||
| 65 | |||||
| 66 | |||||
| 67 | # spent 11.3ms (3.33+7.95) within namespace::clean::import which was called 5 times, avg 2.26ms/call:
# once (1.42ms+3.40ms) by MooseX::Types::Base::BEGIN@16 at line 16 of MooseX/Types/Base.pm
# once (926µs+2.24ms) by MooseX::Types::BEGIN@20 at line 20 of MooseX/Types.pm
# once (539µs+1.26ms) by MooseX::Types::Moose::BEGIN@16 at line 16 of MooseX/Types/Moose.pm
# once (266µs+606µs) by MooseX::Types::CheckedUtilExports::BEGIN@18 at line 18 of MooseX/Types/CheckedUtilExports.pm
# once (175µs+444µs) by namespace::autoclean::BEGIN@16 at line 16 of namespace/autoclean.pm | ||||
| 68 | 5 | 33µs | my ($pragma, @args) = @_; | ||
| 69 | |||||
| 70 | 5 | 14µs | my (%args, $is_explicit); | ||
| 71 | |||||
| 72 | ARG: | ||||
| 73 | 5 | 25µs | while (@args) { | ||
| 74 | |||||
| 75 | 4 | 122µs | 4 | 39µs | if ($args[0] =~ /^\-/) { # spent 39µs making 4 calls to namespace::clean::CORE:match, avg 10µs/call |
| 76 | 4 | 16µs | my $key = shift @args; | ||
| 77 | 4 | 11µs | my $value = shift @args; | ||
| 78 | 4 | 24µs | $args{ $key } = $value; | ||
| 79 | } | ||||
| 80 | else { | ||||
| 81 | $is_explicit++; | ||||
| 82 | last ARG; | ||||
| 83 | } | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | 5 | 40µs | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||
| 87 | 5 | 12µs | if ($is_explicit) { | ||
| 88 | on_scope_end { | ||||
| 89 | $RemoveSubs->($cleanee, {}, @args); | ||||
| 90 | }; | ||||
| 91 | } | ||||
| 92 | else { | ||||
| 93 | |||||
| 94 | # calling class, all current functions and our storage | ||||
| 95 | 5 | 158µs | 5 | 3.97ms | my $functions = $pragma->get_functions($cleanee); # spent 3.97ms making 5 calls to namespace::clean::get_functions, avg 795µs/call |
| 96 | 5 | 81µs | 5 | 916µs | my $store = $pragma->get_class_store($cleanee); # spent 916µs making 5 calls to namespace::clean::get_class_store, avg 183µs/call |
| 97 | 5 | 176µs | 5 | 65µs | my $stash = Package::Stash->new($cleanee); # spent 65µs making 5 calls to Package::Stash::XS::new, avg 13µs/call |
| 98 | |||||
| 99 | # except parameter can be array ref or single value | ||||
| 100 | my %except = map {( $_ => 1 )} ( | ||||
| 101 | $args{ -except } | ||||
| 102 | ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } ) | ||||
| 103 | 5 | 92µs | : () | ||
| 104 | ); | ||||
| 105 | |||||
| 106 | # register symbols for removal, if they have a CODE entry | ||||
| 107 | 5 | 112µs | for my $f (keys %$functions) { | ||
| 108 | 94 | 242µs | next if $except{ $f }; | ||
| 109 | 92 | 3.55ms | 184 | 2.90ms | next unless $stash->has_symbol("&$f"); # spent 2.42ms making 92 calls to Package::Stash::XS::has_symbol, avg 26µs/call
# spent 482µs making 92 calls to Package::Stash::XS::namespace, avg 5µs/call |
| 110 | 92 | 783µs | $store->{remove}{ $f } = 1; | ||
| 111 | } | ||||
| 112 | |||||
| 113 | # register EOF handler on first call to import | ||||
| 114 | 5 | 27µs | unless ($store->{handler_is_installed}) { | ||
| 115 | # spent 31.8ms (190µs+31.6) within namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:117] which was called 5 times, avg 6.35ms/call:
# 5 times (190µs+31.6ms) by B::Hooks::EndOfScope::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/B/Hooks/EndOfScope.pm:26] at line 26 of B/Hooks/EndOfScope.pm, avg 6.35ms/call | ||||
| 116 | 5 | 180µs | 5 | 31.6ms | $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} }); # spent 31.6ms making 5 calls to namespace::clean::__ANON__[namespace/clean.pm:59], avg 6.31ms/call |
| 117 | 5 | 133µs | 5 | 536µs | }; # spent 536µs making 5 calls to B::Hooks::EndOfScope::on_scope_end, avg 107µs/call |
| 118 | 5 | 26µs | $store->{handler_is_installed} = 1; | ||
| 119 | } | ||||
| 120 | |||||
| 121 | 5 | 170µs | return 1; | ||
| 122 | } | ||||
| 123 | } | ||||
| 124 | |||||
| 125 | |||||
| 126 | sub unimport { | ||||
| 127 | my ($pragma, %args) = @_; | ||||
| 128 | |||||
| 129 | # the calling class, the current functions and our storage | ||||
| 130 | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||||
| 131 | my $functions = $pragma->get_functions($cleanee); | ||||
| 132 | my $store = $pragma->get_class_store($cleanee); | ||||
| 133 | |||||
| 134 | # register all unknown previous functions as excluded | ||||
| 135 | for my $f (keys %$functions) { | ||||
| 136 | next if $store->{remove}{ $f } | ||||
| 137 | or $store->{exclude}{ $f }; | ||||
| 138 | $store->{exclude}{ $f } = 1; | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | return 1; | ||||
| 142 | } | ||||
| 143 | |||||
| 144 | |||||
| 145 | # spent 916µs (388+528) within namespace::clean::get_class_store which was called 5 times, avg 183µs/call:
# 5 times (388µs+528µs) by namespace::clean::import at line 96, avg 183µs/call | ||||
| 146 | 5 | 28µs | my ($pragma, $class) = @_; | ||
| 147 | 5 | 158µs | 5 | 72µs | my $stash = Package::Stash->new($class); # spent 72µs making 5 calls to Package::Stash::XS::new, avg 14µs/call |
| 148 | 5 | 26µs | my $var = "%$STORAGE_VAR"; | ||
| 149 | 5 | 457µs | 20 | 370µs | $stash->add_symbol($var, {}) # spent 193µs making 5 calls to Package::Stash::XS::add_symbol, avg 39µs/call
# spent 130µs making 5 calls to Package::Stash::XS::has_symbol, avg 26µs/call
# spent 24µs making 5 calls to Package::Stash::XS::namespace, avg 5µs/call
# spent 24µs making 5 calls to Package::Stash::XS::name, avg 5µs/call |
| 150 | unless $stash->has_symbol($var); | ||||
| 151 | 5 | 257µs | 10 | 158µs | return $stash->get_symbol($var); # spent 134µs making 5 calls to Package::Stash::XS::get_symbol, avg 27µs/call
# spent 24µs making 5 calls to Package::Stash::XS::namespace, avg 5µs/call |
| 152 | } | ||||
| 153 | |||||
| 154 | |||||
| 155 | # spent 3.97ms (1.41+2.56) within namespace::clean::get_functions which was called 5 times, avg 795µs/call:
# 5 times (1.41ms+2.56ms) by namespace::clean::import at line 95, avg 795µs/call | ||||
| 156 | 5 | 21µs | my ($pragma, $class) = @_; | ||
| 157 | |||||
| 158 | 5 | 185µs | 5 | 102µs | my $stash = Package::Stash->new($class); # spent 102µs making 5 calls to Package::Stash::XS::new, avg 20µs/call |
| 159 | return { | ||||
| 160 | 5 | 3.80ms | 198 | 2.96ms | map { $_ => $stash->get_symbol("&$_") } # spent 2.21ms making 94 calls to Package::Stash::XS::get_symbol, avg 24µs/call
# spent 500µs making 99 calls to Package::Stash::XS::namespace, avg 5µs/call
# spent 250µs making 5 calls to Package::Stash::XS::list_all_symbols, avg 50µs/call |
| 161 | $stash->list_all_symbols('CODE') | ||||
| 162 | }; | ||||
| 163 | } | ||||
| 164 | |||||
| 165 | |||||
| 166 | 3 | 119µs | 2 | 208µs | # spent 132µs (56+76) within namespace::clean::BEGIN@166 which was called:
# once (56µs+76µs) by MooseX::Types::Base::BEGIN@16 at line 166 # spent 132µs making 1 call to namespace::clean::BEGIN@166
# spent 76µs making 1 call to warnings::unimport |
| 167 | 1 | 13µs | 'Danger! Laws of Thermodynamics may not apply.' | ||
| 168 | |||||
| 169 | __END__ | ||||
# spent 39µs within namespace::clean::CORE:match which was called 4 times, avg 10µs/call:
# 4 times (39µs+0s) by namespace::clean::import at line 75, avg 10µs/call |