File Coverage

blib/lib/Data/Hopen/G/Node.pm
Criterion Covered Total %
statement 23 23 100.0
branch 8 8 100.0
condition 2 2 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             # Data::Hopen::G::Node - base class for hopen nodes
2             package Data::Hopen::G::Node;
3 12     12   10261 use Data::Hopen;
  12         32  
  12         699  
4 12     12   79 use strict;
  12         27  
  12         262  
5 12     12   61 use Data::Hopen::Base;
  12         20  
  12         79  
6              
7             our $VERSION = '0.000017';
8              
9             sub outputs;
10              
11 12     12   2886 use parent 'Data::Hopen::G::Runnable';
  12         28  
  12         93  
12 12     12   699 use Class::Tiny qw(outputs);
  12         49  
  12         74  
13              
14             =head1 NAME
15              
16             Data::Hopen::G::Node - The base class for all hopen nodes
17              
18             =head1 VARIABLES
19              
20             =head2 outputs
21              
22             Hashref of the outputs from the last time this node was run. Default C<{}>.
23              
24             =cut
25              
26             =head1 FUNCTIONS
27              
28             =head2 outputs
29              
30             Custom accessor for outputs, which enforces the invariant that outputs must
31             be hashrefs.
32              
33             =cut
34              
35             sub outputs {
36 190     190 1 4019 my $self = shift;
37 190 100       5579 croak 'Need an instance' unless $self;
38 189 100       635 if (@_) { # Setter
    100          
39 63 100 100     220 croak "Cannot set `outputs` of @{[$self->name]} to non-hashref " .
  2         9  
40             ($_[0] // '(undef)')
41             unless ref $_[0] eq 'HASH';
42 61         218 return $self->{outputs} = shift;
43             } elsif ( exists $self->{outputs} ) { # Getter
44 125         573 return $self->{outputs};
45             } else { # Default
46 1         6 return +{};
47             }
48             } #outputs()
49              
50             #DEBUG: sub BUILD { use Data::Dumper; say __PACKAGE__,Dumper(\@_); }
51             1;
52             __END__