Evo::Export
version 0.0229
Standart Exporter wasn't good enough for me, so I've written a new one from the scratch
package My::Lib; use Evo '-Export *', -Loaded; # export foo, other as bar sub foo : Export { say 'foo' } sub other : Export(bar) { say 'bar' } # test.pl package main; use Evo 'My::Lib *'; foo(); bar();
use Evo; use Evo 'Evo::Eval eval_try'; use Evo '-Promise promise deferred';
For convenient, you can load all above in one line
use Evo '-Eval eval_try; -Promise promise deferred';
* means load all. - is a shortcut. See ""shortcuts" in Evo
*
-
You can rename subroutines to avoid method clashing
# import promise as prm use Evo '-Promise promise:prm';
You can use * with exclude - for convinient
# import all except "deferred" use Evo '-Promise *, -deferred';
If one name clashes with yours, you can import all except that name and import renamed version of that name
# import all as is but only deferred will be renamed to "renamed_deferred" use Evo '-Promise *, -deferred, deferred:renamed_deferred';
Firstly you need to load Evo::Export with import (or *). This will import import method:
import
use Evo '-Export *'; use Evo '-Export import';
By default, use Your::Module;, without arguments will import nothing. You can change this behaviour to export all without arguments
use Your::Module;
use Evo '-Export import_all:import'; use Evo '-Export *, -import, import_all:import';
Using attribute Export
Export
package My::Lib; use Evo '-Export *'; # or use Evo::Export 'import'; use Evo -Loaded; sub foo : Export { say 'foo' } package main; use Evo 'My::Lib foo'; foo();
Pay attention that module should either import import, or call Evo::Export/install directly (see example below) from import method
Evo::Export/install
You can export with another name
# export as bar sub foo : Export(bar) {say 'foo'}
(EXPERIMENTAL) Using attribte ExportGen
ExportGen
package My::Lib; use Evo '-Export *; -Loaded'; sub bar ($me, $dest) : ExportGen { say qq{"$dest" requested "bar" exported by "$me"}; return sub { say "$me-$dest-bar" }; } package main; use Evo; My::Lib->import('*'); bar();
If you want to write your own import method, do it this way:
package My::Lib; use Evo -Export; # don't import "import" use Evo -Loaded; sub import ($self, @list) { my $dest = scalar caller; Evo::Export->install_in($dest, $self, @list ? @list : ('*')); # force to install all } sub foo : Export { say 'foo' } package main; use Evo 'My::Lib'; foo();
Export signature is more preffered way, but if you wish
# export foo export 'foo'; # export "foo" under name "bar" export 'foo:bar';
Trying to export not existing subroitine will cause an exception
Export function, that won't be available in the source class
# My::Lib now exports foo, but My::Lib::foo doesn't exist export_code foo => sub { say "hello" };
# reexport all from My::Other export_proxy 'My::Other', '*'; # reexport "foo" from My::Other export_proxy 'My::Other', 'foo'; # reexport "foo" from My::Other as "bar" export_proxy 'My::Other', 'foo:bar';
package My::Lib; use Evo '-Export *; -Loaded'; export_gen foo => sub ($me, $dest) { say qq{"$dest" requested "foo" exported by "$me"}; sub {say "hello, $dest"}; }; package main; use Evo; My::Lib->import('*'); foo();
Very powefull and most exciting feature. Evo::Export exports generators, that produces subroutines. Consider it as a 3nd dimension in 3d programming. Better using with ExportGen attribute
By default, this method will be exported and do the stuff. If you need replace import of your module, exclude it by use Evo '-Export *, -import'
use Evo '-Export *, -import'
alexbyk.com
This software is copyright (c) 2016 by alexbyk.
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 Evo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Evo
CPAN shell
perl -MCPAN -e shell install Evo
For more information on module installation, please visit the detailed CPAN module installation guide.