Nephia::Chain - Abstract code chain for hook mechanism of Nephia
Nephia::Chain is an abstract code chain class for hook mechanism of Nephia.
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
Prefix of name for coderef-entries
Enable or Disable name normalization when add and/or search entry.
$chain->append( entryname => sub { ... } );
Add a new coderef to tail of chain.
$chain->prepend( entryname => sub { ... } );
Add a new coderef to head of chain.
$chain->before( 'target', entryname => sub { ... } );
Add a new coderef before target entry.
$chain->after( 'target', entryname => sub { ... } );
Add a new coderef after target entry.
$chain->delete( 'target' );
Delete specified entry.
my $come_from = $chain->from( 'target' );
Returns a class name of origin of specified entry.
my $size = $chain->size;
Returns a number of entries.
my $position = $chain->index( 'target' );
Returns a position number of specified entry.
my @coderef_list = $chain->as_array;
Returns each coderef.
ytnobody <ytnobody@gmail.com>
To install Nephia, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nephia
CPAN shell
perl -MCPAN -e shell install Nephia
For more information on module installation, please visit the detailed CPAN module installation guide.