2 namespace::clean - Keep imports out of your namespace
12 use Carp qw(croak); # will be removed
14 sub bar { 23 } # will be removed
18 sub baz { bar() } # still defined, 'bar' still bound
24 print +(__PACKAGE__->can('croak') ? 'Yes' : 'No'), "\n";
25 print +(__PACKAGE__->can('bar') ? 'Yes' : 'No'), "\n";
26 print +(__PACKAGE__->can('baz') ? 'Yes' : 'No'), "\n";
31 When you define a function, or import one, into a Perl package, it will
32 naturally also be available as a method. This does not per se cause
33 problems, but it can complicate subclassing and, for example, plugin
34 classes that are included by loading them as base classes.
36 The "namespace::clean" pragma will remove all previously declared or
37 imported symbols at the end of the current package's compile cycle. This
38 means that functions are already bound by their name, and calls to them
39 still work. But they will not be available as methods on your class or
43 You shouldn't need to call any of these. Just "use" the package at the
47 Makes a snapshot of the current defined functions and registers a
48 Filter::EOF cleanup routine to remove those symbols from the package at
49 the end of the compile-time.
52 Takes a class as argument and returns all currently defined functions in
53 it as a hash reference with the function name as key and a typeglob
54 reference to the symbol as value.
60 Robert 'phaylon' Sedlacek "<rs@474.at>", with many thanks to Matt S
61 Trout for the inspiration on the whole idea.
64 This program is free software; you can redistribute it and/or modify it
65 under the same terms as perl itself.