Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm |
Statements | Executed 1286 statements in 6.47ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
7 | 1 | 1 | 3.74ms | 30.6ms | __ANON__[:52] | namespace::clean::
1 | 1 | 1 | 1.39ms | 1.75ms | BEGIN@16 | namespace::clean::
7 | 7 | 7 | 1.34ms | 9.78ms | import | namespace::clean::
7 | 1 | 1 | 569µs | 3.88ms | get_functions | namespace::clean::
1 | 1 | 1 | 426µs | 798µs | BEGIN@15 | namespace::clean::
1 | 1 | 1 | 393µs | 10.8ms | BEGIN@17 | namespace::clean::
1 | 1 | 1 | 273µs | 4.32ms | BEGIN@14 | namespace::clean::
7 | 1 | 1 | 179µs | 1.01ms | get_class_store | namespace::clean::
7 | 1 | 1 | 72µs | 30.6ms | __ANON__[:110] | namespace::clean::
1 | 1 | 1 | 19µs | 19µs | BEGIN@2 | namespace::clean::
7 | 1 | 1 | 18µs | 18µs | CORE:match (opcode) | namespace::clean::
1 | 1 | 1 | 14µs | 40µs | BEGIN@159 | namespace::clean::
1 | 1 | 1 | 11µs | 51µs | BEGIN@13 | namespace::clean::
1 | 1 | 1 | 10µs | 20µs | BEGIN@10 | namespace::clean::
1 | 1 | 1 | 10µs | 15µs | BEGIN@11 | namespace::clean::
1 | 1 | 1 | 4µs | 4µ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 19µs within namespace::clean::BEGIN@2 which was called:
# once (19µs+0s) by Hailo::BEGIN@15 at line 4 | ||||
3 | 1 | 6µs | $namespace::clean::AUTHORITY = 'cpan:PHAYLON'; | ||
4 | 1 | 21µs | 1 | 19µs | } # spent 19µs making 1 call to namespace::clean::BEGIN@2 |
5 | # spent 4µs within namespace::clean::BEGIN@5 which was called:
# once (4µs+0s) by Hailo::BEGIN@15 at line 7 | ||||
6 | 1 | 5µs | $namespace::clean::VERSION = '0.18'; | ||
7 | 1 | 16µs | 1 | 4µs | } # spent 4µs making 1 call to namespace::clean::BEGIN@5 |
8 | # ABSTRACT: Keep imports and functions out of your namespace | ||||
9 | |||||
10 | 2 | 23µs | 2 | 28µs | # spent 20µs (10+9) within namespace::clean::BEGIN@10 which was called:
# once (10µs+9µs) by Hailo::BEGIN@15 at line 10 # spent 20µs making 1 call to namespace::clean::BEGIN@10
# spent 9µs making 1 call to warnings::import |
11 | 2 | 26µs | 2 | 20µs | # spent 15µs (10+5) within namespace::clean::BEGIN@11 which was called:
# once (10µs+5µs) by Hailo::BEGIN@15 at line 11 # spent 15µs making 1 call to namespace::clean::BEGIN@11
# spent 5µs making 1 call to strict::import |
12 | |||||
13 | 2 | 32µs | 2 | 91µs | # spent 51µs (11+40) within namespace::clean::BEGIN@13 which was called:
# once (11µs+40µs) by Hailo::BEGIN@15 at line 13 # spent 51µs making 1 call to namespace::clean::BEGIN@13
# spent 40µs making 1 call to vars::import |
14 | 3 | 172µs | 3 | 4.40ms | # spent 4.32ms (273µs+4.05) within namespace::clean::BEGIN@14 which was called:
# once (273µs+4.05ms) by Hailo::BEGIN@15 at line 14 # spent 4.32ms making 1 call to namespace::clean::BEGIN@14
# spent 63µs making 1 call to Exporter::import
# spent 13µs making 1 call to UNIVERSAL::VERSION |
15 | 3 | 137µs | 3 | 875µs | # spent 798µs (426+371) within namespace::clean::BEGIN@15 which was called:
# once (426µs+371µs) by Hailo::BEGIN@15 at line 15 # spent 798µs making 1 call to namespace::clean::BEGIN@15
# spent 66µs making 1 call to Exporter::import
# spent 12µs making 1 call to UNIVERSAL::VERSION |
16 | 3 | 161µs | 2 | 1.76ms | # spent 1.75ms (1.39+361µs) within namespace::clean::BEGIN@16 which was called:
# once (1.39ms+361µs) by Hailo::BEGIN@15 at line 16 # spent 1.75ms making 1 call to namespace::clean::BEGIN@16
# spent 12µs making 1 call to UNIVERSAL::VERSION |
17 | 3 | 766µs | 3 | 11.2ms | # spent 10.8ms (393µs+10.4) within namespace::clean::BEGIN@17 which was called:
# once (393µs+10.4ms) by Hailo::BEGIN@15 at line 17 # spent 10.8ms making 1 call to namespace::clean::BEGIN@17
# spent 349µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
# spent 16µs making 1 call to UNIVERSAL::VERSION |
18 | |||||
19 | 1 | 2µs | $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; | ||
20 | |||||
21 | |||||
22 | # spent 30.6ms (3.74+26.8) 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 7 times, avg 4.37ms/call:
# 7 times (3.74ms+26.8ms) 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.37ms/call | ||||
23 | |||||
24 | 35 | 145µs | my $cleanee = shift; | ||
25 | my $store = shift; | ||||
26 | 7 | 88µs | my $cleanee_stash = Package::Stash->new($cleanee); # spent 88µs making 7 calls to Package::Stash::new, avg 13µs/call | ||
27 | 7 | 488µs | my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee"); # spent 488µs making 7 calls to Package::Stash::new, avg 70µs/call | ||
28 | SYMBOL: | ||||
29 | for my $f (@_) { | ||||
30 | 515 | 1.77ms | my $variable = "&$f"; | ||
31 | # ignore already removed symbols | ||||
32 | next SYMBOL if $store->{exclude}{ $f }; | ||||
33 | |||||
34 | 103 | 3.41ms | next SYMBOL unless $cleanee_stash->has_package_symbol($variable); # spent 3.41ms making 103 calls to Package::Stash::has_package_symbol, avg 33µs/call | ||
35 | |||||
36 | 206 | 1.10ms | 103 | 299µs | if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') { # spent 299µs making 103 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 | 103 | 2.73ms | my $sub = $cleanee_stash->get_package_symbol($variable); # spent 2.73ms making 103 calls to Package::Stash::get_package_symbol, avg 27µs/call | ||
43 | 206 | 1.10ms | if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) { # spent 798µs making 103 calls to Sub::Identify::sub_fullname, avg 8µs/call
# spent 298µs making 103 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 | 103 | 18.7ms | $cleanee_stash->remove_package_symbol($variable); # spent 18.7ms making 103 calls to Package::Stash::remove_package_symbol, avg 182µ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 9.78ms (1.34+8.44) within namespace::clean::import which was called 7 times, avg 1.40ms/call:
# once (202µs+1.34ms) by Hailo::BEGIN@15 at line 15 of Hailo.pm
# once (195µs+1.24ms) by Hailo::Role::Storage::BEGIN@11 at line 11 of Hailo/Role/Storage.pm
# once (195µs+1.21ms) by Hailo::Role::Arguments::BEGIN@11 at line 11 of Hailo/Role/Arguments.pm
# once (201µs+1.20ms) by Hailo::Role::Engine::BEGIN@11 at line 11 of Hailo/Role/Engine.pm
# once (186µs+1.20ms) by Hailo::Role::Tokenizer::BEGIN@11 at line 11 of Hailo/Role/Tokenizer.pm
# once (192µs+1.17ms) by Hailo::Tokenizer::Words::BEGIN@15 at line 15 of Hailo/Tokenizer/Words.pm
# once (173µs+1.08ms) by Hailo::Storage::SQLite::BEGIN@12 at line 12 of Hailo/Storage/SQLite.pm | ||||
61 | 35 | 75µs | my ($pragma, @args) = @_; | ||
62 | |||||
63 | my (%args, $is_explicit); | ||||
64 | |||||
65 | ARG: | ||||
66 | while (@args) { | ||||
67 | |||||
68 | 28 | 102µs | 7 | 18µs | if ($args[0] =~ /^\-/) { # spent 18µs making 7 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 | 49 | 253µ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 | 7 | 3.88ms | my $functions = $pragma->get_functions($cleanee); # spent 3.88ms making 7 calls to namespace::clean::get_functions, avg 555µs/call | ||
89 | 7 | 1.01ms | my $store = $pragma->get_class_store($cleanee); # spent 1.01ms making 7 calls to namespace::clean::get_class_store, avg 144µs/call | ||
90 | 7 | 79µs | my $stash = Package::Stash->new($cleanee); # spent 79µs making 7 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 | 316 | 819µs | next if $except{ $f }; | ||
102 | 103 | 3.23ms | next unless $stash->has_package_symbol("&$f"); # spent 3.23ms making 103 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 | 14 | 63µs | unless ($store->{handler_is_installed}) { | ||
108 | # spent 30.6ms (72µs+30.6) 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 7 times, avg 4.38ms/call:
# 7 times (72µs+30.6ms) 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.38ms/call | ||||
109 | 7 | 72µs | 7 | 30.6ms | $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} }); # spent 30.6ms making 7 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 4.37ms/call |
110 | 7 | 229µs | }; # spent 229µs making 7 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.01ms (179µs+827µs) within namespace::clean::get_class_store which was called 7 times, avg 144µs/call:
# 7 times (179µs+827µs) by namespace::clean::import at line 89, avg 144µs/call | ||||
139 | 35 | 154µs | my ($pragma, $class) = @_; | ||
140 | 7 | 78µs | my $stash = Package::Stash->new($class); # spent 78µs making 7 calls to Package::Stash::new, avg 11µs/call | ||
141 | my $var = "%$STORAGE_VAR"; | ||||
142 | 14 | 557µs | $stash->add_package_symbol($var, {}) # spent 376µs making 7 calls to Package::Stash::add_package_symbol, avg 54µs/call
# spent 181µs making 7 calls to Package::Stash::has_package_symbol, avg 26µs/call | ||
143 | unless $stash->has_package_symbol($var); | ||||
144 | 7 | 192µs | return $stash->get_package_symbol($var); # spent 192µs making 7 calls to Package::Stash::get_package_symbol, avg 27µs/call | ||
145 | } | ||||
146 | |||||
147 | |||||
148 | # spent 3.88ms (569µs+3.32) within namespace::clean::get_functions which was called 7 times, avg 555µs/call:
# 7 times (569µs+3.32ms) by namespace::clean::import at line 88, avg 555µs/call | ||||
149 | 21 | 509µs | my ($pragma, $class) = @_; | ||
150 | |||||
151 | 7 | 113µs | my $stash = Package::Stash->new($class); # spent 113µs making 7 calls to Package::Stash::new, avg 16µs/call | ||
152 | return { | ||||
153 | 117 | 3.20ms | map { $_ => $stash->get_package_symbol("&$_") } # spent 2.98ms making 110 calls to Package::Stash::get_package_symbol, avg 27µs/call
# spent 226µs making 7 calls to Package::Stash::list_all_package_symbols, avg 32µs/call | ||
154 | $stash->list_all_package_symbols('CODE') | ||||
155 | }; | ||||
156 | } | ||||
157 | |||||
158 | |||||
159 | 2 | 24µs | 2 | 66µs | # spent 40µs (14+26) within namespace::clean::BEGIN@159 which was called:
# once (14µs+26µs) by Hailo::BEGIN@15 at line 159 # spent 40µs making 1 call to namespace::clean::BEGIN@159
# spent 26µs making 1 call to warnings::unimport |
160 | 1 | 4µs | 'Danger! Laws of Thermodynamics may not apply.' | ||
161 | |||||
162 | __END__ | ||||
# spent 18µs within namespace::clean::CORE:match which was called 7 times, avg 3µs/call:
# 7 times (18µs+0s) by namespace::clean::import at line 68, avg 3µs/call |