NAME
Evo::Export
VERSION
version 0.0199
DESCRIPTION
Standart Exporter wasn't good enough for me, so I've written a new one from the scratch
SYNOPSYS
# need separate file My/Lib.pm
package My::Lib;
use Evo '-Export *';
# export foo
sub foo : Export { say 'foo' }
# export other as bar
sub other : Export(bar) { say 'bar' }
# test.pl
package main;
use Evo;
use My::Lib '*';
foo();
bar();
IMPORTING
use Evo;
use 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
what to import and how
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';
EXPORTING
Using attribute Export
package main;
use Evo;
{
package My::Lib;
use Evo -Loaded; # don't needed in the real code
use Evo '-Export *';
sub foo : Export {say 'foo'}
}
use My::Lib 'foo';
foo();
Pay attention that module should export '*', to install all unneccessary stuff, including MODIFY_CODE_ATTRIBUTES
and import
. But if you want, you can import them by hand, and this isn't recommended
You can export with another name
# export as bar
sub foo : Export(bar) {say 'foo'}
export '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_anon
Export function, that won't be available in the source class
# My::Lib now exports foo, but My::Lib::foo doesn't exist
export_anon foo => sub { say "hello" };
export_proxy
# 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';
export_gen
package main;
use Evo;
{
# BEGIN and Loaded only for copy-paste example
package My::Lib;
use Evo '-Export *; -Loaded';
export_gen foo => sub ($class) {
say "$class requested me";
sub {"hello, $class"};
};
};
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
Implementation garanties that one module will get the same (cashed) generated unit (if it'l import twice or import from module that reimport the same thing), but different module will get another one
use Evo::Comp 'has';
use Evo::Comp 'has';
has
was imported twice, but generated only once. If some class will do something export_proxy 'Evo::Comp', 'has'
, you can export that has
and it will be the same subroutine
For example, you can use it to check, if requester component has some methods and than use it directly, if $self->method()
isn't good choise
export_gen foo => sub ($class) {
my $method = $class->can("name") or die "provide name";
sub { say $method->() };
};
AUTHOR
alexbyk.com
COPYRIGHT AND LICENSE
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.