Evo::Attr
version 0.0213
Provides a nice way to use attributes without limitations.
# Foo.pm package Foo; use Evo '-Attr attr_handler; -Export import'; attr_handler( sub ($pkg, $code, @attrs) { my @found = grep {/^Foo/} @attrs; my @remaining = grep { !/^Foo/ } @attrs; say "found in $pkg ($code): " . join ', ', @found if @found; @remaining; } ); # test.pl use Evo 'Foo *'; sub foo : Foo {...}
Package that provides attribute should call "attr_handler" with a handler as a first argument. That handler should examine attributes, and return unknown for other handlers.
Provider should also import "import" in Evo::Export to be able to export MODIFY_CODE_ATTRIBUTES into the package, that uses attributes.
MODIFY_CODE_ATTRIBUTES
This approach allow mix different attributes without patching UNIVERSAL.
UNIVERSAL
package Bar; use Evo '-Loaded; -Attr attr_handler; -Export import'; attr_handler( sub ($pkg, $code, @attrs) { my @found = grep {/^Bar/} @attrs; my @remaining = grep { !/^Bar/ } @attrs; say "found in $pkg ($code): " . join ', ', @found if @found; @remaining; } ); # test2.pl use Evo 'Foo *; Bar *'; sub multi : Foo : Bar(args) {...}
This method should be called only once. In fact, it adds MODIFY_CODE_ATTRIBUTES to export list and call internal methods that register handler.
1;
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.