NAME

PNI::Node - is a basic unit of code

SYNOPSIS

# Create a node in a scenario.
use PNI;
my $scenario = PNI::scen;
my $node = $scenario->add_node( type => 'Foo::Bar' );

# Decorate node, add an input and an output.
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

father

my $scenario = $node->father;

Returns father scenario.

ins

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

label

outs

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

type

METHODS

get_ins_edges

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

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.

parents

my @parents = $node->parents;

Returns the list of nodes which outs are connected to this node ins.

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.