NAME

PNI::Node - is a basic unit of code

SYNOPSIS

# Define "Foo::Bar" node.
# in file PNI/Node/Foo/Bar.pm

package PNI::Node::Foo::Bar;
use PNI::Node::Mo;
extends 'PNI::Node';

sub BUILD {
    my $self = shift;

    # Decorate node, add an input and an output.
    $self->in('lead');
    $self->out('gold');

}

sub task {
    my $self = shift;

    my $in  = $self->in('lead');
    my $out = $self->out('gold');

    # Turn lead into gold.
    ...

      $out->data( $in->data );

}

1;

# Somewhere else in your code.

# Create a "Foo::Bar" node.
use PNI::Node;
my $node = PNI::Node->new( type => 'Foo::Bar' );

my $in  = $node->in('lead');
my $out = $node->out('gold');

# Fill input data.
$in->data('1Kg');

# Produce something.
$node->task;

# Get output data.
my $gold = $out->data;

ATTRIBUTES

ins

my @ins = $node->ins->list;

Holds a PNI::Set of <PNI::In>.

label

outs

my @outs = $node->outs->list;

Holds a PNI::Set of <PNI::Out>.

type

METHODS

by_id

use PNI::Node;

my $node = PNI::Node::by_id($node_id);

Given a node id, returns a reference to the node.

get_ins_edges

my @ins_edges = $node->get_ins_edges;

Returns a list of all PNI::Edge connected to node ins.

get_outs_edges

my @outs_edges = $node->get_outs_edges;

Returns a list of all PNI::Edge connected to node outs.

in

$node->in('input_name');

Creates an input by the given name if such input does not exists.

my $in = $node->in('input_name');

Returns a PNI::In object.

$node->in->data(1);
say $node->in->data;

Default input name is 'in', so you can be lazy.

$node->in(1);
$node->in('in1'); # idem

If you pass digit x as input_name, it will be replaced by inx.

is_on

$node->task if $node->is_on;

off

$node->off;

Turn off a node if something is wrong.

sub task {
    my $self = shift;

    # if "in" is not defined, return and turn off the node.
    $self->in->is_defined or return $self->off;
}

on

out

$node->out('output_name');

Creates an output by the given name if such output does not exists.

my $out = $node->out('output_name');

Returns a PNI::Out object.

$node->out->data(1);
say $node->out->data;

Default output name is 'out', so you can be lazy.

$node->out(1);
$node->out('out1'); # ditto

If you pass digit x as output_name, it will be replaced by outx.

task

$node->task;

This is an abstract method that must be implemented by every class that extends PNI::Node. It is the chunk of code that the node implements.

to_hashref

my $node_hashref = $node->to_hashref;

Returns an hash ref representing the node.