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

NAME

CHI::Cascade::Rule - a rule class

SYNOPSIS

    $cascade->rule(
        target  => qr/^target_(\d+)$/,
        depends => 'base_target',
        code    => sub {
            my ( $rule, $target, $dep_values ) = @_;

            # An execution of $cascade->run('target_12') will pass in code a $rule as:
            #
            # $rule->target     eq      $target
            # $rule->depends    ===     [ 'base_target' ]
            # $rule->qr_params  ===     ( 12 )
            # $rule->params     ==      [ 1, 2, 3 ]
        },
        params  => [ 1, 2, 3 ]
    );

    $cascade->run('target_12');

CONSTRUCTOR

An instance of this object is created by CHI::Cascade in "rule" in CHI::Cascade as a following:

    $rule = CHI::Cascade::Rule->new( %options )

The list of options please see in "rule( %options )" in CHI::Cascade method.

DESCRIPTION

The instance of this object is passed to "code" in CHI::Cascade, "coderef" in CHI::Cascade, "recomputed" in CHI::Cascade, "depends_catch" in CHI::Cascade by CHI::Cascade as first argument (The API of running this code was changed since v0.16). You can use it object as accessor to some parameters of your currect executed target.

METHODS

qr_params

returns a list. It is used for getting a result of =~ operation if target is described for rule through qr// operator.

depends

returns arrayref of dependencies (depends option of rule method) even if one scalar value is passed there (as one dependence). Always is defined even there no defined depends option for rule. If 'depends' is coderef you will get a returned value of one. If any item of depends array is code it will be executed too. To see more details in "depends" in CHI::Cascade.

target()

returns current target as plain text after matching.

params()

returns any data of any type what were passed to "params" in CHI::Cascade

cascade()

returns reference to CHI::Cascade instance object for this rule.

stash()

It returns hashref to a stash. A stash is hash for temporary data between rule's codes. It can be used only from inside call stack of "run" in CHI::Cascade. Example:

    $cascade->run( 'target', stash => { key1 => value1 } )

and into rule's code:

    $rule->stash->{key1}

If a "run" in CHI::Cascade method didn't get stash hashref the default stash will be as empty hash. You can pass a data between rule's codes but it's recommended only in special cases. For example when run's target cannot get a full data from its target's name.

value_expires

Sets an CHI's cache expire value for the target marker of this value to be created by this rule in notation described in "DURATION EXPRESSIONS" in CHI. The default is 'never'. It can be coderef or string scalar format as "DURATION EXPRESSIONS" in CHI. A coderef to be called as $coderef->($rule) and should return expire time as string value. You can use this method inside "code" in CHI::Cascade and "recomputed" in CHI::Cascade your callbacks if you want to force recomputing of current target through minimum this time.

AUTHOR

This module has been written by Perlover <perlover@perlover.com>

LICENSE

This module is free software and is published under the same terms as Perl itself.

SEE ALSO

CHI::Cascade