Evo::Class::Out
version 0.0213
Inside-out driver for Evo::Class using Hash::Util::FieldHash. Makes possible to use any type of references as objects.
package main; use Evo; { package My::Spy; use Evo '-Class::Out *'; has 'foo', required => 1; } my $foo = My::Spy->init(sub { say "foo" }, foo => 'FOO'); say $foo->foo; $foo->();
Evo::Class::Out supports the same features as Evo::Class::Hash, but is a little (20-30%, maybe twice), slower. But allow to use any references, that can be blessed, as objects
Evo::Class::Hash
Instead of new, it provides init. So you can desing new, for example, as a clousure by yourself
new
init
In this example we created spy object, that logs all invocations. You can make the similar thing with overloading with the hash-class too, but this implementation has one advantage: it's a real codered and reftype returns CODE, not HASH.
codered
reftype
CODE
HASH
package main; use Evo; use Scalar::Util 'reftype'; { package My::Spy; use Evo '-Class::Out *'; use Scalar::Util 'weaken'; has calls => sub { [] }; has 'fn', required => 1; sub new { my $copy; $copy = my $sub = sub { push $copy->calls->@*, [@_]; $copy->fn->(@_); }; weaken $copy; init($sub, @_); $sub; } } my $spy = My::Spy->new(fn => sub { local $, = ';'; say "hello", @_ }); say reftype $spy; $spy->(); $spy->(1); $spy->(1, 2); local $, = ''; say "logged: ", $_->@* for $spy->calls->@*;
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.