The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Evo::Attr

VERSION

version 0.0213

DESCRIPTION

Provides a nice way to use attributes without limitations.

SYNOPSYS

  # 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 {...}

USAGE

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.

This approach allow mix different attributes without patching 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) {...}

attr_handler

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;

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.