NAME
Evo::Manager - Perl Evo manager
VERSION
version 0.012
SYNOPSIS
use Evo::Base -strict;
use Evo::Manager;
use Evo::Wrappers 'w_dsl_init';
my $mngr = Evo::Manager->new;
my $way = $mngr->build_way;
my $train = $mngr->build_train(way => $way);
my $curry = $mngr->curry_wrappers(w_dsl_init);
$curry->(sub { say keys $mngr->current->%* })->($mngr->build_train);
my @args = qw(1 2);
my $stash = {foo => 'bar'};
$mngr->dsl_call($stash, @args, sub { say $mngr->current('foo'); say @_ });
# see more example in Evo.pm docs
DESCRIPTION
Your can consider a manager as a builder + organazer. That was made to make a usage simple. This class subclasses Railway::Builder and provide a glue to make features working together with a less typing.
METHODS
default_curry
A default curry function, bassed to Evo::Way instances. Dont't make this as an attribute while subclassing, unless you are sure what you want
check_current
my $context = $mngr->check_current;
my $exists = $mngr->check_current('key');
Safely check a current context without throwing an extention.
current
Work with current context
# get all context
my $current = $mngr->current;
# get value by key
my $val = $mngr->current('key');
# set value once
$mngr->current('new' => 'val')->current('new');
Thows an error when is called outside dsl. Throws an error if key doesn't exist Throws an error on attempts to override existing key. You can also use "check_current" or as hash referrence, but in most cases if you get an error, you're doing something wrong.
dsl_call
Invoke a callback with dsl. First argument is "current" context, last is a code referrence, others will be passed as arguments
$mngr->dsl_call({}, 1, 2, sub { });
$mngr->dsl_call({foo => 2}, sub { say $mngr->current('foo') });
dsl_extend (Experimental)
$mngr->dsl_call(
{foo => 2},
sub {
local $, = '; ';
say keys $mngr->current->%*;
$mngr->dsl_extend({bar => 3}, sub { say keys $mngr->current->%*; });
say keys $mngr->current->%*;
}
);
Extends current dsl with keys from first argument for invocation of the last one. Others will be passed as arguments. You still can'not override existing keys. Thows an expection outside dsl
run_wrappers
my $wrapped = $mngr->run_wrappers(@wrappers, $cb);
Run wrappers for a callback in reverse order. Wrappers are higher-order functions. See an examples in synopsis or "w_dsl_init" in Evo::Wrappers Or wait for an article
Returns a last argument, if it is the only one and no wrappers provided
curry_wrappers
my $curry = $mngr->curry_wrappers(@wrappers);
my $curried = $curry->($cb);
$curried->();
my @extra_wrappers;
$curry->(@extra_wrappers, $cb)->();
Creates a curry function for wrappers, that invokes "run_wrappers" with given list + passed arguments.
singleton Singleton - the same instance will be returned for every invocation
my $single = Evo::Manager->singleton;
dsl_depth
A depth of recurcive L</"dsl_call"> or L</"dsl_extend"> invocations by
instance. C<0> means we are not in the dsl
dsl_global_depth
The same as L</"dsl_depth"> but calculates all invocations of all instances.
ATTENTION
Curry isn't a real currying function, it's a partial function. But I have no idea how to name it. So it's a subject to change in the future (and all relayed attributes)
=build_way
Builds a Evo::Way instance passing a result of invocation "default_curry" to it as a "curry" in Evo::Way attribute.
AUTHOR
alexbyk.com
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 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.