Satoshi Azuma > Nephia-0.85 > Nephia::Chain

Download:
Nephia-0.85.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source   Latest Release: Nephia-0.87

NAME ^

Nephia::Chain - Abstract code chain for hook mechanism of Nephia

DESCRIPTION ^

Nephia::Chain is an abstract code chain class for hook mechanism of Nephia.

SYNOPSIS ^

    my $chain = Nephia::Chain->new(namespace => 'Foobar::Chain::Item');
    $chain->append(incr => sub { $_[0] + 1 }, double => sub { $_[0] * 2 }); ### y = ((x + 1) * 2)
    $chain->prepend(power => sub { $_[0] ** 2 });                           ### y = (((x ** 2) + 1) * 2)
    $chain->before('Head', plus3 => sub { $_[0] + 3 });                     ### y = ((((x + 3) ** 2) + 1) * 2)
    $chain->after('plus3', half => sub { $_[0] / 2 });                      ### y = (((((x + 3) / 2) ** 2) + 1) * 2)
    
    my $x = 3;
    for my $item ( $chain->as_array ) {
        $x = $item->($x);
    }
    my $y = $x;
    printf "y = %s\n", $y; ### 20

ATTRIBUTES ^

namespace

Prefix of name for coderef-entries

name_normalize

Enable or Disable name normalization when add and/or search entry.

METHODS ^

append

    $chain->append( entryname => sub { ... } );

Add a new coderef to tail of chain.

prepend

    $chain->prepend( entryname => sub { ... } );

Add a new coderef to head of chain.

before

    $chain->before( 'target', entryname => sub { ... } );

Add a new coderef before target entry.

after

    $chain->after( 'target', entryname => sub { ... } );

Add a new coderef after target entry.

delete

    $chain->delete( 'target' );

Delete specified entry.

from

    my $come_from = $chain->from( 'target' );

Returns a class name of origin of specified entry.

size

    my $size = $chain->size;

Returns a number of entries.

index

    my $position = $chain->index( 'target' );

Returns a position number of specified entry.

as_array

    my @coderef_list = $chain->as_array;

Returns each coderef.

AUTHOR ^

ytnobody <ytnobody@gmail.com>

syntax highlighting: