Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm |
Statements | Executed 1632 statements in 7.98ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
9 | 1 | 1 | 4.72ms | 37.9ms | __ANON__[:52] | namespace::clean::
9 | 9 | 9 | 1.68ms | 12.3ms | import | namespace::clean::
1 | 1 | 1 | 1.42ms | 1.77ms | BEGIN@16 | namespace::clean::
9 | 1 | 1 | 720µs | 4.87ms | get_functions | namespace::clean::
1 | 1 | 1 | 454µs | 812µs | BEGIN@15 | namespace::clean::
1 | 1 | 1 | 380µs | 2.61ms | BEGIN@17 | namespace::clean::
1 | 1 | 1 | 239µs | 866µs | BEGIN@14 | namespace::clean::
9 | 1 | 1 | 225µs | 1.28ms | get_class_store | namespace::clean::
9 | 1 | 1 | 90µs | 38.0ms | __ANON__[:110] | namespace::clean::
9 | 1 | 1 | 26µs | 26µs | CORE:match (opcode) | namespace::clean::
1 | 1 | 1 | 18µs | 18µs | BEGIN@2 | namespace::clean::
1 | 1 | 1 | 16µs | 59µs | BEGIN@13 | namespace::clean::
1 | 1 | 1 | 16µs | 50µs | BEGIN@159 | namespace::clean::
1 | 1 | 1 | 12µs | 18µs | BEGIN@11 | namespace::clean::
1 | 1 | 1 | 11µs | 21µs | BEGIN@10 | namespace::clean::
1 | 1 | 1 | 5µs | 5µs | BEGIN@5 | namespace::clean::
0 | 0 | 0 | 0s | 0s | __ANON__[:83] | namespace::clean::
0 | 0 | 0 | 0s | 0s | clean_subroutines | namespace::clean::
0 | 0 | 0 | 0s | 0s | unimport | namespace::clean::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package namespace::clean; | ||||
2 | # spent 18µs within namespace::clean::BEGIN@2 which was called:
# once (18µs+0s) by Hailo::Command::BEGIN@7 at line 4 | ||||
3 | 1 | 6µs | $namespace::clean::AUTHORITY = 'cpan:PHAYLON'; | ||
4 | 1 | 22µs | 1 | 18µs | } # spent 18µs making 1 call to namespace::clean::BEGIN@2 |
5 | # spent 5µs within namespace::clean::BEGIN@5 which was called:
# once (5µs+0s) by Hailo::Command::BEGIN@7 at line 7 | ||||
6 | 1 | 6µs | $namespace::clean::VERSION = '0.18'; | ||
7 | 1 | 17µs | 1 | 5µs | } # spent 5µs making 1 call to namespace::clean::BEGIN@5 |
8 | # ABSTRACT: Keep imports and functions out of your namespace | ||||
9 | |||||
10 | 2 | 24µs | 2 | 31µs | # spent 21µs (11+10) within namespace::clean::BEGIN@10 which was called:
# once (11µs+10µs) by Hailo::Command::BEGIN@7 at line 10 # spent 21µs making 1 call to namespace::clean::BEGIN@10
# spent 10µs making 1 call to warnings::import |
11 | 2 | 27µs | 2 | 24µs | # spent 18µs (12+6) within namespace::clean::BEGIN@11 which was called:
# once (12µs+6µs) by Hailo::Command::BEGIN@7 at line 11 # spent 18µs making 1 call to namespace::clean::BEGIN@11
# spent 6µs making 1 call to strict::import |
12 | |||||
13 | 2 | 31µs | 2 | 101µs | # spent 59µs (16+42) within namespace::clean::BEGIN@13 which was called:
# once (16µs+42µs) by Hailo::Command::BEGIN@7 at line 13 # spent 59µs making 1 call to namespace::clean::BEGIN@13
# spent 42µs making 1 call to vars::import |
14 | 3 | 153µs | 3 | 947µs | # spent 866µs (239+626) within namespace::clean::BEGIN@14 which was called:
# once (239µs+626µs) by Hailo::Command::BEGIN@7 at line 14 # spent 866µs making 1 call to namespace::clean::BEGIN@14
# spent 69µs making 1 call to Exporter::import
# spent 12µs making 1 call to UNIVERSAL::VERSION |
15 | 3 | 146µs | 3 | 897µs | # spent 812µs (454+358) within namespace::clean::BEGIN@15 which was called:
# once (454µs+358µs) by Hailo::Command::BEGIN@7 at line 15 # spent 812µs making 1 call to namespace::clean::BEGIN@15
# spent 68µs making 1 call to Exporter::import
# spent 16µs making 1 call to UNIVERSAL::VERSION |
16 | 3 | 160µs | 2 | 1.78ms | # spent 1.77ms (1.42+354µs) within namespace::clean::BEGIN@16 which was called:
# once (1.42ms+354µs) by Hailo::Command::BEGIN@7 at line 16 # spent 1.77ms making 1 call to namespace::clean::BEGIN@16
# spent 13µs making 1 call to UNIVERSAL::VERSION |
17 | 3 | 947µs | 3 | 2.98ms | # spent 2.61ms (380µs+2.23) within namespace::clean::BEGIN@17 which was called:
# once (380µs+2.23ms) by Hailo::Command::BEGIN@7 at line 17 # spent 2.61ms making 1 call to namespace::clean::BEGIN@17
# spent 362µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
# spent 14µs making 1 call to UNIVERSAL::VERSION |
18 | |||||
19 | 1 | 2µs | $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; | ||
20 | |||||
21 | |||||
22 | # spent 37.9ms (4.72+33.2) within namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:52] which was called 9 times, avg 4.21ms/call:
# 9 times (4.72ms+33.2ms) by namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:110] at line 109, avg 4.21ms/call | ||||
23 | |||||
24 | 45 | 182µs | my $cleanee = shift; | ||
25 | my $store = shift; | ||||
26 | 9 | 113µs | my $cleanee_stash = Package::Stash->new($cleanee); # spent 113µs making 9 calls to Package::Stash::new, avg 13µs/call | ||
27 | 9 | 133µs | my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee"); # spent 133µs making 9 calls to Package::Stash::new, avg 15µs/call | ||
28 | SYMBOL: | ||||
29 | for my $f (@_) { | ||||
30 | 655 | 2.27ms | my $variable = "&$f"; | ||
31 | # ignore already removed symbols | ||||
32 | next SYMBOL if $store->{exclude}{ $f }; | ||||
33 | |||||
34 | 131 | 4.23ms | next SYMBOL unless $cleanee_stash->has_package_symbol($variable); # spent 4.23ms making 131 calls to Package::Stash::has_package_symbol, avg 32µs/call | ||
35 | |||||
36 | 262 | 1.37ms | 131 | 384µs | if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') { # spent 384µs making 131 calls to Package::Stash::namespace, avg 3µ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 | 131 | 3.46ms | my $sub = $cleanee_stash->get_package_symbol($variable); # spent 3.46ms making 131 calls to Package::Stash::get_package_symbol, avg 26µs/call | ||
43 | 262 | 1.37ms | if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) { # spent 988µs making 131 calls to Sub::Identify::sub_fullname, avg 8µs/call
# spent 383µs making 131 calls to Package::Stash::name, avg 3µ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 | 131 | 23.5ms | $cleanee_stash->remove_package_symbol($variable); # spent 23.5ms making 131 calls to Package::Stash::remove_package_symbol, avg 179µs/call | ||
51 | } | ||||
52 | 1 | 4µs | }; | ||
53 | |||||
54 | sub clean_subroutines { | ||||
55 | my ($nc, $cleanee, @subs) = @_; | ||||
56 | $RemoveSubs->($cleanee, {}, @subs); | ||||
57 | } | ||||
58 | |||||
59 | |||||
60 | # spent 12.3ms (1.68+10.6) within namespace::clean::import which was called 9 times, avg 1.37ms/call:
# once (199µs+1.26ms) by Hailo::BEGIN@9 at line 9 of lib/Hailo.pm
# once (192µs+1.22ms) by Hailo::Role::Arguments::BEGIN@5 at line 5 of lib/Hailo/Role/Arguments.pm
# once (192µs+1.21ms) by Hailo::Role::Engine::BEGIN@5 at line 5 of lib/Hailo/Role/Engine.pm
# once (188µs+1.19ms) by hailo::BEGIN@9 at line 9 of bin/hailo
# once (182µs+1.19ms) by Hailo::Role::Tokenizer::BEGIN@5 at line 5 of lib/Hailo/Role/Tokenizer.pm
# once (182µs+1.17ms) by Hailo::Role::Storage::BEGIN@5 at line 5 of lib/Hailo/Role/Storage.pm
# once (193µs+1.16ms) by Hailo::Tokenizer::Words::BEGIN@9 at line 9 of lib/Hailo/Tokenizer/Words.pm
# once (173µs+1.12ms) by Hailo::Storage::SQLite::BEGIN@6 at line 6 of lib/Hailo/Storage/SQLite.pm
# once (175µs+1.11ms) by Hailo::Command::BEGIN@7 at line 7 of lib/Hailo/Command.pm | ||||
61 | 45 | 91µs | my ($pragma, @args) = @_; | ||
62 | |||||
63 | my (%args, $is_explicit); | ||||
64 | |||||
65 | ARG: | ||||
66 | while (@args) { | ||||
67 | |||||
68 | 36 | 142µs | 9 | 26µs | if ($args[0] =~ /^\-/) { # spent 26µs making 9 calls to namespace::clean::CORE:match, avg 3µ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 | 63 | 316µ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 | 9 | 4.87ms | my $functions = $pragma->get_functions($cleanee); # spent 4.87ms making 9 calls to namespace::clean::get_functions, avg 541µs/call | ||
89 | 9 | 1.28ms | my $store = $pragma->get_class_store($cleanee); # spent 1.28ms making 9 calls to namespace::clean::get_class_store, avg 142µs/call | ||
90 | 9 | 100µs | my $stash = Package::Stash->new($cleanee); # spent 100µs making 9 calls to Package::Stash::new, avg 11µ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 | 402 | 1.02ms | next if $except{ $f }; | ||
102 | 131 | 4.04ms | next unless $stash->has_package_symbol("&$f"); # spent 4.04ms making 131 calls to Package::Stash::has_package_symbol, avg 31µs/call | ||
103 | $store->{remove}{ $f } = 1; | ||||
104 | } | ||||
105 | |||||
106 | # register EOF handler on first call to import | ||||
107 | 18 | 79µs | unless ($store->{handler_is_installed}) { | ||
108 | # spent 38.0ms (90µs+37.9) within namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:110] which was called 9 times, avg 4.22ms/call:
# 9 times (90µs+37.9ms) by B::Hooks::EndOfScope::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/B/Hooks/EndOfScope.pm:26] at line 26 of B/Hooks/EndOfScope.pm, avg 4.22ms/call | ||||
109 | 9 | 89µs | 9 | 37.9ms | $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} }); # spent 37.9ms making 9 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 4.21ms/call |
110 | 9 | 301µs | }; # spent 301µs making 9 calls to B::Hooks::EndOfScope::on_scope_end, avg 33µ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 1.28ms (225µs+1.06) within namespace::clean::get_class_store which was called 9 times, avg 142µs/call:
# 9 times (225µs+1.06ms) by namespace::clean::import at line 89, avg 142µs/call | ||||
139 | 45 | 201µs | my ($pragma, $class) = @_; | ||
140 | 9 | 102µs | my $stash = Package::Stash->new($class); # spent 102µs making 9 calls to Package::Stash::new, avg 11µs/call | ||
141 | my $var = "%$STORAGE_VAR"; | ||||
142 | 18 | 709µs | $stash->add_package_symbol($var, {}) # spent 466µs making 9 calls to Package::Stash::add_package_symbol, avg 52µs/call
# spent 243µs making 9 calls to Package::Stash::has_package_symbol, avg 27µs/call | ||
143 | unless $stash->has_package_symbol($var); | ||||
144 | 9 | 245µs | return $stash->get_package_symbol($var); # spent 245µs making 9 calls to Package::Stash::get_package_symbol, avg 27µs/call | ||
145 | } | ||||
146 | |||||
147 | |||||
148 | # spent 4.87ms (720µs+4.15) within namespace::clean::get_functions which was called 9 times, avg 541µs/call:
# 9 times (720µs+4.15ms) by namespace::clean::import at line 88, avg 541µs/call | ||||
149 | 27 | 638µs | my ($pragma, $class) = @_; | ||
150 | |||||
151 | 9 | 142µs | my $stash = Package::Stash->new($class); # spent 142µs making 9 calls to Package::Stash::new, avg 16µs/call | ||
152 | return { | ||||
153 | 149 | 4.01ms | map { $_ => $stash->get_package_symbol("&$_") } # spent 3.74ms making 140 calls to Package::Stash::get_package_symbol, avg 27µs/call
# spent 271µs making 9 calls to Package::Stash::list_all_package_symbols, avg 30µs/call | ||
154 | $stash->list_all_package_symbols('CODE') | ||||
155 | }; | ||||
156 | } | ||||
157 | |||||
158 | |||||
159 | 2 | 27µs | 2 | 85µs | # spent 50µs (16+35) within namespace::clean::BEGIN@159 which was called:
# once (16µs+35µs) by Hailo::Command::BEGIN@7 at line 159 # spent 50µs making 1 call to namespace::clean::BEGIN@159
# spent 35µs making 1 call to warnings::unimport |
160 | 1 | 4µs | 'Danger! Laws of Thermodynamics may not apply.' | ||
161 | |||||
162 | __END__ | ||||
# spent 26µs within namespace::clean::CORE:match which was called 9 times, avg 3µs/call:
# 9 times (26µs+0s) by namespace::clean::import at line 68, avg 3µs/call |