← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:12 2010

File /usr/local/share/perl/5.10.0/namespace/autoclean.pm
Statements Executed 149
Total Time 0.0022565 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
711539µs10.1msnamespace::autoclean::::__ANON__[:57]namespace::autoclean::__ANON__[:57]
777241µs425µsnamespace::autoclean::::importnamespace::autoclean::import
0000s0snamespace::autoclean::::BEGINnamespace::autoclean::BEGIN
0000s0snamespace::autoclean::::__ANON__[:25]namespace::autoclean::__ANON__[:25]
0000s0snamespace::autoclean::::__ANON__[:26]namespace::autoclean::__ANON__[:26]
0000s0snamespace::autoclean::::__ANON__[:27]namespace::autoclean::__ANON__[:27]
0000s0snamespace::autoclean::::__ANON__[:33]namespace::autoclean::__ANON__[:33]
0000s0snamespace::autoclean::::__ANON__[:51]namespace::autoclean::__ANON__[:51]
LineStmts.Exclusive
Time
Avg.Code
1330µs10µsuse strict;
# spent 9µs making 1 call to strict::import
2352µs17µsuse warnings;
# spent 24µs making 1 call to warnings::import
3
4package namespace::autoclean;
5BEGIN {
611µs1µs $namespace::autoclean::AUTHORITY = 'cpan:FLORA';
7125µs25µs}
8BEGIN {
911µs1µs $namespace::autoclean::VERSION = '0.11';
10125µs25µs}
11# ABSTRACT: Keep imports out of your namespace
12
133166µs55µsuse Class::MOP 0.80;
# spent 32µs making 1 call to UNIVERSAL::VERSION # spent 3µs making 1 call to import
143184µs62µsuse B::Hooks::EndOfScope;
15345µs15µsuse List::Util qw( first );
# spent 57µs making 1 call to Exporter::import
163658µs219µsuse namespace::clean 0.11;
# spent 254µs making 1 call to namespace::clean::import # spent 23µs making 1 call to UNIVERSAL::VERSION
17
18
19sub import {
20717µs2µs my ($class, %args) = @_;
21
22 my $subcast = sub {
23 my $i = shift;
24 return $i if ref $i eq 'CODE';
25 return sub { $_ =~ $i } if ref $i eq 'Regexp';
26 return sub { $_ eq $i };
27736µs5µs };
28
29 my $runtest = sub {
30 my ($code, $method_name) = @_;
31 local $_ = $method_name;
32 return $code->();
33728µs4µs };
34
35718µs3µs my $cleanee = exists $args{-cleanee} ? $args{-cleanee} : scalar caller;
36
37 my @also = map { $subcast->($_) } (
38 exists $args{-also}
39712µs2µs ? (ref $args{-also} eq 'ARRAY' ? @{ $args{-also} } : $args{-also})
40 : ()
41 );
42
43
# spent 10.1ms (539µs+9.54) within namespace::autoclean::__ANON__[/usr/local/share/perl/5.10.0/namespace/autoclean.pm:57] which was called 7 times, avg 1.44ms/call: # 7 times (539µs+9.54ms) by B::Hooks::EndOfScope::__ANON__[/usr/local/share/perl/5.10.0/B/Hooks/EndOfScope.pm:47] at line 47 of /usr/local/share/perl/5.10.0/B/Hooks/EndOfScope.pm, avg 1.44ms/call
on_scope_end {
44744µs6µs my $meta = Class::MOP::Class->initialize($cleanee);
# spent 106µs making 7 calls to Class::MOP::Class::initialize, avg 15µs/call
457128µs18µs my %methods = map { ($_ => 1) } $meta->get_method_list;
# spent 7.46ms making 7 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 1.07ms/call
467121µs17µs $methods{meta} = 1 if $meta->isa('Moose::Meta::Role') && Moose->VERSION < 0.90;
# spent 109µs making 7 calls to UNIVERSAL::isa, avg 16µs/call
4776µs814ns my %extra = ();
48
49749µs7µs for my $method (keys %methods) {
501714µs847ns next if exists $extra{$_};
5117148µs9µs next unless first { $runtest->($_, $method) } @also;
# spent 49µs making 17 calls to List::Util::first, avg 3µs/call
52 $extra{ $method } = 1;
53 }
54
557203µs29µs my @symbols = keys %{ $meta->get_all_package_symbols('CODE') };
# spent 114µs making 7 calls to Class::MOP::Package::get_all_package_symbols, avg 16µs/call
567114µs16µs namespace::clean->clean_subroutines($cleanee, keys %extra, grep { !$methods{$_} } @symbols);
# spent 1.70ms making 7 calls to namespace::clean::clean_subroutines, avg 243µs/call
577116µs17µs };
# spent 185µs making 7 calls to B::Hooks::EndOfScope::on_scope_end, avg 26µs/call
58}
59
6014µs4µs1;
61
62110µs10µs__END__
63=pod
64
65=head1 NAME
66
67namespace::autoclean - Keep imports out of your namespace
68
69=head1 SYNOPSIS
70
71 package Foo;
72 use namespace::autoclean;
73 use Some::Package qw/imported_function/;
74
75 sub bar { imported_function('stuff') }
76
77 # later on:
78 Foo->bar; # works
79 Foo->imported_function; # will fail. imported_function got cleaned after compilation
80
81=head1 DESCRIPTION
82
83When you import a function into a Perl package, it will naturally also be
84available as a method.
85
86The C<namespace::autoclean> pragma will remove all imported symbols at the end
87of the current package's compile cycle. Functions called in the package itself
88will still be bound by their name, but they won't show up as methods on your
89class or instances.
90
91This module is very similar to L<namespace::clean|namespace::clean>, except it
92will clean all imported functions, no matter if you imported them before or
93after you C<use>d the pragma. It will also not touch anything that looks like a
94method, according to C<Class::MOP::Class::get_method_list>.
95
96If you're writing an exporter and you want to clean up after yourself (and your
97peers), you can use the C<-cleanee> switch to specify what package to clean:
98
99 package My::MooseX::namespace::autoclean;
100 use strict;
101
102 use namespace::autoclean (); # no cleanup, just load
103
104 sub import {
105 namespace::autoclean->import(
106 -cleanee => scalar(caller),
107 );
108 }
109
110=head1 PARAMETERS
111
112=head2 -also => [ ITEM | REGEX | SUB, .. ]
113
114=head2 -also => ITEM
115
116=head2 -also => REGEX
117
118=head2 -also => SUB
119
120Sometimes you don't want to clean imports only, but also helper functions
121you're using in your methods. The C<-also> switch can be used to declare a list
122of functions that should be removed additional to any imports:
123
124 use namespace::autoclean -also => ['some_function', 'another_function'];
125
126If only one function needs to be additionally cleaned the C<-also> switch also
127accepts a plain string:
128
129 use namespace::autoclean -also => 'some_function';
130
131In some situations, you may wish for a more I<powerful> cleaning solution.
132
133The C<-also> switch can take a Regex or a CodeRef to match against local
134function names to clean.
135
136 use namespace::autoclean -also => qr/^_/
137
138 use namespace::autoclean -also => sub { $_ =~ m{^_} };
139
140 use namespace::autoclean -also => [qr/^_/ , qr/^hidden_/ ];
141
142 use namespace::autoclean -also => [sub { $_ =~ m/^_/ or $_ =~ m/^hidden/ }, sub { uc($_) == $_ } ];
143
144=head1 SEE ALSO
145
146L<namespace::clean>
147
148L<Class::MOP>
149
150L<B::Hooks::EndOfScope>
151
152=head1 AUTHOR
153
154 Florian Ragwitz <rafl@debian.org>
155
156=head1 COPYRIGHT AND LICENSE
157
158This software is copyright (c) 2010 by Florian Ragwitz.
159
160This is free software; you can redistribute it and/or modify it under
161the same terms as the Perl 5 programming language system itself.
162
163=cut
164