Since the very, very early days of Sub::Exporter, it was clear that it would be
really useful to be able to replace the way that exporting itself occurs. That
is: the way that routines are generated and installed, based on configuration,
gathered collections, and other user arguments to the generated
In the past, it was possible to replace this, but only by relying on an (intentionally) awful and undocumented interface. The routine worked something like this:
_do_importon each one
_do_importcleans up the pair and some associated configuration
_do_importcalls the "exporter"
_generateto build the installable routine
_installto install the routine
The "exporter" is the thing that was supposed to be pluggable. In fact, Sub::Exporter::Util contains an alternate exporter. The problem was that the interface stank, and I didn't want to publish an interface until I had one I liked... but the possible uses are huge. I use it in the Sub::Exporter test suite to test what would have been done, basically letting me instrument the system. Dieter and I were talking about making a way to gather information about what has exported where for a kind of cheap metadata about what roles have been built where, and how. (This would be needed as part of my long-standing mixin factory idea, and as part of the roles stuff Dieter wants to work on.)
Finally, spurred on by outside demand (that is, Dieter), I made a first pass at implementation last night. I think it's pretty good!
_do_importcalls the generator for each pair, generating a new arrayref
_do_importthe exporter, passing the new arrayref and some other info
Now there are two publicly defined callbacks that can be provided, either for
your whole exporting package (passed as part of the
-setup for Sub::Exporter)
or per call to
import, as part of the optional initial hashref.
I'm hoping to see and create some fun new behaviors.
This code is on the CPAN as Sub::Exporter 0.977_01. It's a big step toward 1.000.