Importer::Zim::EndOfScope - Import functions with compilation block scope
version 0.4.0
use Importer::Zim::EndOfScope 'Scalar::Util' => 'blessed'; use Importer::Zim::EndOfScope 'Scalar::Util' => ( 'blessed' => { -as => 'typeof' } ); use Importer::Zim::EndOfScope 'Mango::BSON' => ':bson'; use Importer::Zim::EndOfScope 'Foo' => { -version => '3.0' } => 'foo'; use Importer::Zim::EndOfScope 'SpaceTime::Machine' => [qw(robot rubber_pig)];
"Wait a minute! What planet is this?" – Zim
This is a backend for Importer::Zim which makes imported symbols available during the compilation of the surrounding scope.
Unlike Importer::Zim::Lexical, it works for perls before 5.18. Unlike Importer::Zim::Lexical which plays with lexical subs, this meddles with the symbol tables for a (hopefully short) time interval. (This time interval should be even shorter than the one that applies to Importer::Zim::Unit.)
The statement
use Importer::Zim::EndOfScope 'Foo' => 'foo';
works sort of
use B::Hooks::EndOfScope; my $_OLD_SUBS; BEGIN { require Foo; $_OLD_SUBS = Sub::Replace::sub_replace('foo' => \&Foo::foo); } on_scope_end { Sub::Replace::sub_replace($_OLD_SUBS); }
That means:
Imported subroutines are installed into the caller namespace at compile time.
Imported subroutines are cleaned up after perl finished compiling the surrounding scope.
See Sub::Replace for a few gotchas about why this is not simply done with Perl statements such as
*foo = \&Foo::foo;
You can set the IMPORTER_ZIM_DEBUG environment variable for get some diagnostics information printed to STDERR.
IMPORTER_ZIM_DEBUG
STDERR
IMPORTER_ZIM_DEBUG=1
Importer::Zim
B::Hooks::EndOfScope
Importer::Zim::Lexical
Adriano Ferreira <ferreira@cpan.org>
This software is copyright (c) 2017 by Adriano Ferreira.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Importer::Zim::EndOfScope, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Importer::Zim::EndOfScope
CPAN shell
perl -MCPAN -e shell install Importer::Zim::EndOfScope
For more information on module installation, please visit the detailed CPAN module installation guide.