File Coverage

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 13     13   12548 use Data::Hopen;
  13         31  
  13         1089  
4 13     13   80 use strict;
  13         38  
  13         446  
5 13     13   77 use Data::Hopen::Base;
  13         34  
  13         88  
6              
7             our $VERSION = '0.000021';
8              
9             sub outputs;
10              
11 13     13   3899 use parent 'Data::Hopen::G::Runnable';
  13         28  
  13         99  
12 13     13   1073 use Class::Tiny qw(outputs);
  13         29  
  13         75  
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 8017 my $self = shift;
37 190 100       860 croak 'Need an instance' unless $self;
38 189 100       650 if (@_) { # Setter
    100          
39 63 100 100     244 croak "Cannot set `outputs` of @{[$self->name]} to non-hashref " .
  2         11  
40             ($_[0] // '(undef)')
41             unless ref $_[0] eq 'HASH';
42 61         265 return $self->{outputs} = shift;
43             } elsif ( exists $self->{outputs} ) { # Getter
44 125         728 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__