← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/getfix
  Run on Thu May 20 15:30:03 2010
Reported on Thu May 20 16:25:39 2010

File/wise/base/static/lib/perl5/site_perl/5.10.0/Exporter/Lite.pm
Statements Executed279
Total Time0.000912 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1414100.000550.00099Exporter::Lite::import
14110.000440.00044Exporter::Lite::_export
00000Exporter::Lite::_not_exported

LineStmts.Exclusive
Time
Avg.Code
1package Exporter::Lite;
2
312.8e-52.8e-5require 5.004;
4
5# Using strict or vars almost doubles our load time. Turn them back
6# on when debugging.
7#use strict 'vars'; # we're going to be doing a lot of sym refs
8#use vars qw($VERSION @EXPORT);
9
1011.8e-51.8e-5$VERSION = 0.02;
1111.0e-61.0e-6@EXPORT = qw(import); # we'll know pretty fast if it doesn't work :)
12
13
14
15sub import {
16560.000264.6e-6 my($exporter, @imports) = @_;
17 my($caller, $file, $line) = caller;
18
1941.7e-54.2e-6 unless( @imports ) { # Default import.
20 @imports = @{$exporter.'::EXPORT'};
21 }
22 else {
23 # Because @EXPORT_OK = () would indicate that nothing is
24 # to be exported, we cannot simply check the length of @EXPORT_OK.
25 # We must to oddness to see if the variable exists at all as
26 # well as avoid autovivification.
27 # XXX idea stolen from base.pm, this might be all unnecessary
28 my $eokglob;
2927.0e-63.5e-6 if( $eokglob = ${$exporter.'::'}{EXPORT_OK} and *$eokglob{ARRAY} ) {
3069.0e-51.5e-5 if( @{$exporter.'::EXPORT_OK'} ) {
31 # This can also be cached.
32 my %ok = map { s/^&//; $_ => 1 } @{$exporter.'::EXPORT_OK'},
33665.4e-58.2e-7 @{$exporter.'::EXPORT'};
34
35664.7e-57.1e-7 my($denied) = grep {s/^&//; !$ok{$_}} @imports;
36 _not_exported($denied, $exporter, $file, $line) if $denied;
37 }
38 else { # We don't export anything.
39 _not_exported($imports[0], $exporter, $file, $line);
40 }
41 }
42 }
43
44 _export($caller, $exporter, @imports);
# spent 442µs making 14 calls to Exporter::Lite::_export, avg 32µs/call
45}
46
47
48
49
# spent 442µs within Exporter::Lite::_export which was called 14 times, avg 32µs/call: # 14 times (442µs+0) by Exporter::Lite::import at line 44, avg 32µs/call
sub _export {
50280.000103.7e-6 my($caller, $exporter, @imports) = @_;
51
52 # Stole this from Exporter::Heavy. I'm sure it can be written better
53 # but I'm lazy at the moment.
54 foreach my $sym (@imports) {
55 # shortcut for the common case of no type character
56470.000286.0e-6 (*{$caller.'::'.$sym} = \&{$exporter.'::'.$sym}, next)
57 unless $sym =~ s/^(\W)//;
58
59 my $type = $1;
60 my $caller_sym = $caller.'::'.$sym;
61 my $export_sym = $exporter.'::'.$sym;
62 *{$caller_sym} =
63 $type eq '&' ? \&{$export_sym} :
64 $type eq '$' ? \${$export_sym} :
65 $type eq '@' ? \@{$export_sym} :
66 $type eq '%' ? \%{$export_sym} :
67 $type eq '*' ? *{$export_sym} :
68 do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
69 }
70}
71
72
73#"#
74sub _not_exported {
75 my($thing, $exporter, $file, $line) = @_;
76 die sprintf qq|"%s" is not exported by the %s module at %s line %d\n|,
77 $thing, $exporter, $file, $line;
78}
79
8017.0e-67.0e-61;
81
82__END__
83
84=head1 NAME
85
86Exporter::Lite - Lightweight exporting of variables
87
88=head1 SYNOPSIS
89
90 package Foo;
91 use Exporter::Lite;
92
93 # Just like Exporter.
94 @EXPORT = qw($This That);
95 @EXPORT_OK = qw(@Left %Right);
96
97
98 # Meanwhile, in another piece of code!
99 package Bar;
100 use Foo; # exports $This and &That.
101
102
103=head1 DESCRIPTION
104
105This is an alternative to Exporter intended to provide a lightweight
106subset of its functionality. It supports C<import()>, C<@EXPORT> and
107C<@EXPORT_OK> and not a whole lot else.
108
109Unlike Exporter, it is not necessary to inherit from Exporter::Lite
110(ie. no C<@ISA = qw(Exporter::Lite)> mantra). Exporter::Lite simply
111exports its import() function. This might be called a "mix-in".
112
113Setting up a module to export its variables and functions is simple:
114
115 package My::Module;
116 use Exporter::Lite;
117
118 @EXPORT = qw($Foo bar);
119
120now when you C<use My::Module>, C<$Foo> and C<bar()> will show up.
121
122In order to make exporting optional, use @EXPORT_OK.
123
124 package My::Module;
125 use Exporter::Lite;
126
127 @EXPORT_OK = qw($Foo bar);
128
129when My::Module is used, C<$Foo> and C<bar()> will I<not> show up.
130You have to ask for them. C<use My::Module qw($Foo bar)>.
131
132=head1 Methods
133
134Export::Lite has one public method, import(), which is called
135automaticly when your modules is use()'d.
136
137In normal usage you don't have to worry about this at all.
138
139=over 4
140
141=item B<import>
142
143 Some::Module->import;
144 Some::Module->import(@symbols);
145
146Works just like C<Exporter::import()> excepting it only honors
147@Some::Module::EXPORT and @Some::Module::EXPORT_OK.
148
149The given @symbols are exported to the current package provided they
150are in @Some::Module::EXPORT or @Some::Module::EXPORT_OK. Otherwise
151an exception is thrown (ie. the program dies).
152
153If @symbols is not given, everything in @Some::Module::EXPORT is
154exported.
155
156=back
157
158=head1 DIAGNOSTICS
159
160=over 4
161
162=item '"%s" is not exported by the %s module'
163
164Attempted to import a symbol which is not in @EXPORT or @EXPORT_OK.
165
166=item 'Can\'t export symbol: %s'
167
168Attempted to import a symbol of an unknown type (ie. the leading $@% salad
169wasn't recognized).
170
171=back
172
173=head1 BUGS and CAVEATS
174
175Its not yet clear if this is actually any lighter or faster than
176Exporter. I know its at least on par.
177
178OTOH, the docs are much clearer and not having to say C<@ISA =
179qw(Exporter)> is kinda nice.
180
181=head1 AUTHORS
182
183Michael G Schwern <schwern@pobox.com>
184
185=head1 LICENSE
186
187This program is free software; you can redistribute it and/or
188modify it under the same terms as Perl itself.
189
190See F<http://www.perl.com/perl/misc/Artistic.html>
191
192=head1 SEE ALSO
193
194L<Exporter>, L<Exporter::Simple>, L<UNIVERSAL::exports>
195
196=cut