| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm |
| Statements | Executed 6581 statements in 81.4ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 54 | 2 | 1 | 87.1ms | 746ms | namespace::clean::__ANON__[:52] |
| 5 | 5 | 5 | 3.15ms | 24.1ms | namespace::clean::import |
| 49 | 1 | 1 | 2.13ms | 667ms | namespace::clean::clean_subroutines |
| 1 | 1 | 1 | 1.79ms | 3.10ms | namespace::clean::BEGIN@15 |
| 5 | 1 | 1 | 1.73ms | 9.82ms | namespace::clean::get_functions |
| 1 | 1 | 1 | 1.66ms | 9.05ms | namespace::clean::BEGIN@17 |
| 5 | 1 | 1 | 402µs | 2.11ms | namespace::clean::get_class_store |
| 5 | 1 | 1 | 186µs | 81.3ms | namespace::clean::__ANON__[:110] |
| 1 | 1 | 1 | 75µs | 387µs | namespace::clean::BEGIN@14 |
| 1 | 1 | 1 | 59µs | 137µs | namespace::clean::BEGIN@159 |
| 1 | 1 | 1 | 53µs | 104µs | namespace::clean::BEGIN@16 |
| 1 | 1 | 1 | 46µs | 46µs | namespace::clean::BEGIN@2 |
| 1 | 1 | 1 | 41µs | 111µs | namespace::clean::BEGIN@10 |
| 4 | 1 | 1 | 37µs | 37µs | namespace::clean::CORE:match (opcode) |
| 1 | 1 | 1 | 36µs | 52µs | namespace::clean::BEGIN@11 |
| 1 | 1 | 1 | 35µs | 149µs | namespace::clean::BEGIN@13 |
| 1 | 1 | 1 | 16µs | 16µs | namespace::clean::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | namespace::clean::__ANON__[:83] |
| 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 46µs within namespace::clean::BEGIN@2 which was called:
# once (46µs+0s) by MooseX::Types::Base::BEGIN@16 at line 4 | ||||
| 3 | 1 | 26µs | $namespace::clean::AUTHORITY = 'cpan:PHAYLON'; | ||
| 4 | 1 | 86µs | 1 | 46µs | } # spent 46µs making 1 call to namespace::clean::BEGIN@2 |
| 5 | # spent 16µs within namespace::clean::BEGIN@5 which was called:
# once (16µs+0s) by MooseX::Types::Base::BEGIN@16 at line 7 | ||||
| 6 | 1 | 17µs | $namespace::clean::VERSION = '0.18'; | ||
| 7 | 1 | 79µs | 1 | 16µs | } # spent 16µs making 1 call to namespace::clean::BEGIN@5 |
| 8 | # ABSTRACT: Keep imports and functions out of your namespace | ||||
| 9 | |||||
| 10 | 3 | 98µs | 2 | 182µs | # spent 111µs (41+71) within namespace::clean::BEGIN@10 which was called:
# once (41µs+71µs) by MooseX::Types::Base::BEGIN@16 at line 10 # spent 111µs making 1 call to namespace::clean::BEGIN@10
# spent 70µs making 1 call to warnings::import |
| 11 | 3 | 101µs | 2 | 67µs | # spent 52µs (36+15) within namespace::clean::BEGIN@11 which was called:
# once (36µs+15µs) by MooseX::Types::Base::BEGIN@16 at line 11 # spent 52µs making 1 call to namespace::clean::BEGIN@11
# spent 15µs making 1 call to strict::import |
| 12 | |||||
| 13 | 3 | 111µs | 2 | 264µs | # spent 149µs (35+114) within namespace::clean::BEGIN@13 which was called:
# once (35µs+114µs) by MooseX::Types::Base::BEGIN@16 at line 13 # spent 149µs making 1 call to namespace::clean::BEGIN@13
# spent 114µs making 1 call to vars::import |
| 14 | 3 | 295µs | 3 | 700µs | # spent 387µs (75+312) within namespace::clean::BEGIN@14 which was called:
# once (75µs+312µs) by MooseX::Types::Base::BEGIN@16 at line 14 # spent 387µs making 1 call to namespace::clean::BEGIN@14
# spent 188µs making 1 call to Exporter::import
# spent 124µs making 1 call to UNIVERSAL::VERSION |
| 15 | 3 | 551µs | 3 | 3.41ms | # spent 3.10ms (1.79+1.31) within namespace::clean::BEGIN@15 which was called:
# once (1.79ms+1.31ms) by MooseX::Types::Base::BEGIN@16 at line 15 # spent 3.10ms making 1 call to namespace::clean::BEGIN@15
# spent 256µs making 1 call to Exporter::import
# spent 55µs making 1 call to UNIVERSAL::VERSION |
| 16 | 3 | 177µs | 2 | 156µs | # spent 104µs (53+52) within namespace::clean::BEGIN@16 which was called:
# once (53µs+52µs) by MooseX::Types::Base::BEGIN@16 at line 16 # spent 104µs making 1 call to namespace::clean::BEGIN@16
# spent 52µs making 1 call to UNIVERSAL::VERSION |
| 17 | 3 | 3.08ms | 3 | 10.2ms | # spent 9.05ms (1.66+7.39) within namespace::clean::BEGIN@17 which was called:
# once (1.66ms+7.39ms) by MooseX::Types::Base::BEGIN@16 at line 17 # spent 9.05ms making 1 call to namespace::clean::BEGIN@17
# spent 1.10ms 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 746ms (87.1+659) within namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:52] which was called 54 times, avg 13.8ms/call:
# 49 times (77.7ms+588ms) by namespace::clean::clean_subroutines at line 56, avg 13.6ms/call
# 5 times (9.44ms+71.7ms) by namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:110] at line 109, avg 16.2ms/call | ||||
| 23 | |||||
| 24 | 270 | 3.17ms | my $cleanee = shift; | ||
| 25 | my $store = shift; | ||||
| 26 | 54 | 2.35ms | my $cleanee_stash = Package::Stash->new($cleanee); # spent 2.35ms making 54 calls to Package::Stash::new, avg 44µs/call | ||
| 27 | 54 | 2.51ms | my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee"); # spent 2.51ms making 54 calls to Package::Stash::new, avg 46µs/call | ||
| 28 | SYMBOL: | ||||
| 29 | for my $f (@_) { | ||||
| 30 | 4125 | 40.2ms | my $variable = "&$f"; | ||
| 31 | # ignore already removed symbols | ||||
| 32 | next SYMBOL if $store->{exclude}{ $f }; | ||||
| 33 | |||||
| 34 | 825 | 82.2ms | next SYMBOL unless $cleanee_stash->has_package_symbol($variable); # spent 82.2ms making 825 calls to Package::Stash::has_package_symbol, avg 100µs/call | ||
| 35 | |||||
| 36 | 1650 | 26.3ms | 825 | 7.31ms | if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') { # spent 7.31ms making 825 calls to Package::Stash::namespace, avg 9µ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 | 65.7ms | my $sub = $cleanee_stash->get_package_symbol($variable); # spent 65.7ms making 825 calls to Package::Stash::get_package_symbol, avg 80µs/call | ||
| 43 | 1650 | 30.0ms | if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) { # spent 21.8ms making 825 calls to Sub::Identify::sub_fullname, avg 26µs/call
# spent 8.28ms making 825 calls to Package::Stash::name, avg 10µs/call | ||
| 44 | my $new_fq = $deleted_stash->name . "::$f"; | ||||
| 45 | subname($new_fq, $sub); | ||||
| 46 | $deleted_stash->add_package_symbol($variable, $sub); | ||||
| 47 | } | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | 825 | 469ms | $cleanee_stash->remove_package_symbol($variable); # spent 469ms making 825 calls to Package::Stash::remove_package_symbol, avg 569µs/call | ||
| 51 | } | ||||
| 52 | 1 | 16µs | }; | ||
| 53 | |||||
| 54 | # spent 667ms (2.13+665) within namespace::clean::clean_subroutines which was called 49 times, avg 13.6ms/call:
# 49 times (2.13ms+665ms) 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 13.6ms/call | ||||
| 55 | 98 | 2.05ms | my ($nc, $cleanee, @subs) = @_; | ||
| 56 | 49 | 665ms | $RemoveSubs->($cleanee, {}, @subs); # spent 665ms making 49 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 13.6ms/call | ||
| 57 | } | ||||
| 58 | |||||
| 59 | |||||
| 60 | # spent 24.1ms (3.15+21.0) within namespace::clean::import which was called 5 times, avg 4.82ms/call:
# once (1.00ms+7.37ms) by MooseX::Types::BEGIN@20 at line 20 of MooseX/Types.pm
# once (1.09ms+7.15ms) by MooseX::Types::Base::BEGIN@16 at line 16 of MooseX/Types/Base.pm
# once (593µs+3.83ms) by MooseX::Types::Moose::BEGIN@16 at line 16 of MooseX/Types/Moose.pm
# once (284µs+1.46ms) by MooseX::Types::CheckedUtilExports::BEGIN@18 at line 18 of MooseX/Types/CheckedUtilExports.pm
# once (186µs+1.14ms) by namespace::autoclean::BEGIN@16 at line 16 of namespace/autoclean.pm | ||||
| 61 | 25 | 124µs | my ($pragma, @args) = @_; | ||
| 62 | |||||
| 63 | my (%args, $is_explicit); | ||||
| 64 | |||||
| 65 | ARG: | ||||
| 66 | while (@args) { | ||||
| 67 | |||||
| 68 | 16 | 180µs | 4 | 37µs | if ($args[0] =~ /^\-/) { # spent 37µs making 4 calls to namespace::clean::CORE:match, avg 9µs/call |
| 69 | my $key = shift @args; | ||||
| 70 | my $value = shift @args; | ||||
| 71 | $args{ $key } = $value; | ||||
| 72 | } | ||||
| 73 | else { | ||||
| 74 | $is_explicit++; | ||||
| 75 | last ARG; | ||||
| 76 | } | ||||
| 77 | } | ||||
| 78 | |||||
| 79 | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||||
| 80 | 35 | 627µs | if ($is_explicit) { | ||
| 81 | on_scope_end { | ||||
| 82 | $RemoveSubs->($cleanee, {}, @args); | ||||
| 83 | }; | ||||
| 84 | } | ||||
| 85 | else { | ||||
| 86 | |||||
| 87 | # calling class, all current functions and our storage | ||||
| 88 | 5 | 9.82ms | my $functions = $pragma->get_functions($cleanee); # spent 9.82ms making 5 calls to namespace::clean::get_functions, avg 1.96ms/call | ||
| 89 | 5 | 2.11ms | my $store = $pragma->get_class_store($cleanee); # spent 2.11ms making 5 calls to namespace::clean::get_class_store, avg 423µs/call | ||
| 90 | 5 | 161µs | my $stash = Package::Stash->new($cleanee); # spent 161µs making 5 calls to Package::Stash::new, avg 32µs/call | ||
| 91 | |||||
| 92 | # except parameter can be array ref or single value | ||||
| 93 | my %except = map {( $_ => 1 )} ( | ||||
| 94 | $args{ -except } | ||||
| 95 | ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } ) | ||||
| 96 | : () | ||||
| 97 | ); | ||||
| 98 | |||||
| 99 | # register symbols for removal, if they have a CODE entry | ||||
| 100 | for my $f (keys %$functions) { | ||||
| 101 | 278 | 1.94ms | next if $except{ $f }; | ||
| 102 | 92 | 8.36ms | next unless $stash->has_package_symbol("&$f"); # spent 8.36ms making 92 calls to Package::Stash::has_package_symbol, avg 91µs/call | ||
| 103 | $store->{remove}{ $f } = 1; | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | # register EOF handler on first call to import | ||||
| 107 | 10 | 151µs | unless ($store->{handler_is_installed}) { | ||
| 108 | # spent 81.3ms (186µs+81.1) within namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:110] which was called 5 times, avg 16.3ms/call:
# 5 times (186µs+81.1ms) 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 16.3ms/call | ||||
| 109 | 5 | 182µs | 5 | 81.1ms | $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} }); # spent 81.1ms making 5 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 16.2ms/call |
| 110 | 5 | 465µs | }; # spent 465µs making 5 calls to B::Hooks::EndOfScope::on_scope_end, avg 93µs/call | ||
| 111 | $store->{handler_is_installed} = 1; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | return 1; | ||||
| 115 | } | ||||
| 116 | } | ||||
| 117 | |||||
| 118 | |||||
| 119 | sub unimport { | ||||
| 120 | my ($pragma, %args) = @_; | ||||
| 121 | |||||
| 122 | # the calling class, the current functions and our storage | ||||
| 123 | my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller; | ||||
| 124 | my $functions = $pragma->get_functions($cleanee); | ||||
| 125 | my $store = $pragma->get_class_store($cleanee); | ||||
| 126 | |||||
| 127 | # register all unknown previous functions as excluded | ||||
| 128 | for my $f (keys %$functions) { | ||||
| 129 | next if $store->{remove}{ $f } | ||||
| 130 | or $store->{exclude}{ $f }; | ||||
| 131 | $store->{exclude}{ $f } = 1; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | return 1; | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | |||||
| 138 | # spent 2.11ms (402µs+1.71) within namespace::clean::get_class_store which was called 5 times, avg 423µs/call:
# 5 times (402µs+1.71ms) by namespace::clean::import at line 89, avg 423µs/call | ||||
| 139 | 25 | 321µs | my ($pragma, $class) = @_; | ||
| 140 | 5 | 171µs | my $stash = Package::Stash->new($class); # spent 171µs making 5 calls to Package::Stash::new, avg 34µs/call | ||
| 141 | my $var = "%$STORAGE_VAR"; | ||||
| 142 | 10 | 1.15ms | $stash->add_package_symbol($var, {}) # spent 759µs making 5 calls to Package::Stash::add_package_symbol, avg 152µs/call
# spent 388µs making 5 calls to Package::Stash::has_package_symbol, avg 78µs/call | ||
| 143 | unless $stash->has_package_symbol($var); | ||||
| 144 | 5 | 394µs | return $stash->get_package_symbol($var); # spent 394µs making 5 calls to Package::Stash::get_package_symbol, avg 79µs/call | ||
| 145 | } | ||||
| 146 | |||||
| 147 | |||||
| 148 | # spent 9.82ms (1.73+8.08) within namespace::clean::get_functions which was called 5 times, avg 1.96ms/call:
# 5 times (1.73ms+8.08ms) by namespace::clean::import at line 88, avg 1.96ms/call | ||||
| 149 | 15 | 1.43ms | my ($pragma, $class) = @_; | ||
| 150 | |||||
| 151 | 5 | 220µs | my $stash = Package::Stash->new($class); # spent 220µs making 5 calls to Package::Stash::new, avg 44µs/call | ||
| 152 | return { | ||||
| 153 | 99 | 7.86ms | map { $_ => $stash->get_package_symbol("&$_") } # spent 7.21ms making 94 calls to Package::Stash::get_package_symbol, avg 77µs/call
# spent 650µs making 5 calls to Package::Stash::list_all_package_symbols, avg 130µs/call | ||
| 154 | $stash->list_all_package_symbols('CODE') | ||||
| 155 | }; | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | |||||
| 159 | 3 | 110µs | 2 | 215µs | # spent 137µs (59+78) within namespace::clean::BEGIN@159 which was called:
# once (59µs+78µs) by MooseX::Types::Base::BEGIN@16 at line 159 # spent 137µs making 1 call to namespace::clean::BEGIN@159
# spent 78µs making 1 call to warnings::unimport |
| 160 | 1 | 13µs | 'Danger! Laws of Thermodynamics may not apply.' | ||
| 161 | |||||
| 162 | __END__ | ||||
# spent 37µs within namespace::clean::CORE:match which was called 4 times, avg 9µs/call:
# 4 times (37µs+0s) by namespace::clean::import at line 68, avg 9µs/call |