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
22 sub quux { baz() } # will be removed again
31 print +(__PACKAGE__->can('croak') ? 'Yes' : 'No'), "\n";
32 print +(__PACKAGE__->can('bar') ? 'Yes' : 'No'), "\n";
33 print +(__PACKAGE__->can('baz') ? 'Yes' : 'No'), "\n";
34 print +(__PACKAGE__->can('quux') ? 'Yes' : 'No'), "\n";
39 When you define a function, or import one, into a Perl package, it will
40 naturally also be available as a method. This does not per se cause
41 problems, but it can complicate subclassing and, for example, plugin
42 classes that are included by loading them as base classes.
44 The "namespace::clean" pragma will remove all previously declared or
45 imported symbols at the end of the current package's compile cycle. This
46 means that functions are already bound by their name, and calls to them
47 still work. But they will not be available as methods on your class or
51 You shouldn't need to call any of these. Just "use" the package at the
55 Makes a snapshot of the current defined functions and registers a
56 Filter::EOF cleanup routine to remove those symbols from the package at
57 the end of the compile-time.
60 This method will be called when you do a
64 It will start a new section of code that defines functions to clean up.
67 This returns a reference to a hash in your package containing
68 information about function names included and excluded from removal.
71 Takes a class as argument and returns all currently defined functions in
72 it as a hash reference with the function name as key and a typeglob
73 reference to the symbol as value.
79 Robert 'phaylon' Sedlacek "<rs@474.at>", with many thanks to Matt S
80 Trout for the inspiration on the whole idea.
83 This program is free software; you can redistribute it and/or modify it
84 under the same terms as perl itself.