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   10364 use Data::Hopen;
  12         30  
  12         675  
4 12     12   82 use strict;
  12         37  
  12         261  
5 12     12   66 use Data::Hopen::Base;
  12         24  
  12         82  
6              
7             our $VERSION = '0.000019';
8              
9             sub outputs;
10              
11 12     12   2886 use parent 'Data::Hopen::G::Runnable';
  12         26  
  12         87  
12 12     12   775 use Class::Tiny qw(outputs);
  12         24  
  12         70  
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 3103 my $self = shift;
37 190 100       5661 croak 'Need an instance' unless $self;
38 189 100       585 if (@_) { # Setter
    100          
39 63 100 100     197 croak "Cannot set `outputs` of @{[$self->name]} to non-hashref " .
  2         11  
40             ($_[0] // '(undef)')
41             unless ref $_[0] eq 'HASH';
42 61         202 return $self->{outputs} = shift;
43             } elsif ( exists $self->{outputs} ) { # Getter
44 125         573 return $self->{outputs};
45             } else { # Default
46 1         9 return +{};
47             }
48             } #outputs()
49              
50             #DEBUG: sub BUILD { use Data::Dumper; say __PACKAGE__,Dumper(\@_); }
51             1;
52             __END__