Importer::Zim

As a proof-of-concept, Importer::Zim has been released to CPAN. For modules which export symbols and define @EXPORT, @EXPORT_OK and @EXPORT_TAGS, zim can be used as a pragma to import subroutines into the caller package with lexical scope for perl 5.18+.

use zim 'Scalar::Util' => qw(blessed);
use zim 'List::Util' => qw(first sum max any all);

use zim 'Fcntl' => ':flock';
use zim 'Carp';  # imports carp(), confess(), croak()

use zim 'Mango' => 'bson_time' => { -as => 'bson_dt' };

Some of the benefits are:

  • there is no need for Exporter-like code - only the declarations of the exported symbols are necessary.

  • the imported symbols are self-cleaning - which means they won't pollute the namespace like it happens when exporting / importing is done through the symbol tables. (No need for modules like namespace::clean or namespace::autoclean.)

Importers are on the side of the consumer code - which is the one that should care more about the effect of the imported symbols. On the other hand, exporters are on the side of the producer code which can hardly anticipate every possible way its subroutines will be used. There are more good points on importers vs exporters at https://metacpan.org/pod/Importer#WHY?

2 Comments

The synopsis should demonstrate the availability/non-availability in scopes and contrast it with what Exporter does normally.

I don't get the Invader Zim reference. I couldn't find any piggys or tacos in the documentation!

Leave a comment

About Adriano Ferreira

user-pic I blog about Perl.