File Coverage

blib/lib/Build/Hopen/G/Entity.pm
Criterion Covered Total %
statement 14 15 93.3
branch 4 6 66.6
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             # Build::Hopen::G::Entity - base class for hopen's data model
2             package Build::Hopen::G::Entity;
3 9     9   3679 use Build::Hopen;
  9         17  
  9         392  
4 9     9   46 use Build::Hopen::Base;
  9         13  
  9         50  
5              
6             our $VERSION = '0.000006'; # TRIAL
7              
8             sub name;
9              
10 9     9   2603 use Class::Tiny qw(name);
  9         2906  
  9         40  
11              
12             =head1 NAME
13              
14             Build::Hopen::G::Entity - The base class for all hopen nodes and edges
15              
16             =head1 SYNOPSIS
17              
18             hopen creates and manages a graph of entities: nodes and edges. This class
19             holds common information.
20              
21             =head1 MEMBERS
22              
23             =head2 name
24              
25             The name of this entity. The name is for human consumption and is not used by
26             hopen to make any decisions. However, node names starting with an underscore
27             are reserved for hopen's internal use.
28              
29             The name C<'0'> (a single digit zero) is forbidden (since it's falsy).
30              
31             =cut
32              
33             =head1 FUNCTIONS
34              
35             =head2 name
36              
37             A custom accessor for name. If no name has been stored, return the stringifed
38             version of the entity. That way every entity always has a name.
39              
40             =cut
41              
42             sub name {
43 41 50   41 1 6403 my $self = shift or croak 'Need an instance';
44 41 100       123 if (@_) { # Setter
    50          
45 7         19 return $self->{name} = shift;
46             } elsif ( exists $self->{name} ) { # Getter
47 34         138 return $self->{name};
48             } else { # Default
49 0         0 return "$self";
50             }
51             } #name()
52              
53             =head2 has_custom_name
54              
55             Returns truthy if a name has been set using L.
56              
57             =cut
58              
59 2     2 1 11 sub has_custom_name { !!(shift)->{name} }
60              
61             1;
62             __END__