File Coverage

lib/Object/Meta/Named/List.pm
Criterion Covered Total %
statement 27 29 93.1
branch 5 10 50.0
condition 3 9 33.3
subroutine 6 6 100.0
pod 3 3 100.0
total 44 57 77.1


line stmt bran cond sub pod time code
1             # @author Bodo (Hugo) Barwich
2             # @version 2025-10-24
3             # @package Indexed List by Name
4             # @subpackage classes_metanames.pm
5              
6             # This Module defines Classes to manage Data indexed in a List by its Name
7             #
8             #---------------------------------
9             # Requirements:
10             # - The Perl Package "perl-Digest-MD5" must be installed
11             # - The Perl Package "perl-Data-Dump" must be installed
12             #
13             #---------------------------------
14             # Features:
15             # path /object-meta/lib/Object/Meta/Named/List.pm
16              
17             #==============================================================================
18             # The Object::Meta::Named::List Package
19              
20             =head1 NAME
21              
22             Object::Meta::Named::List - Library to index C instances by
23             their C field.
24              
25             =cut
26              
27             package Object::Meta::Named::List;
28              
29             #----------------------------------------------------------------------------
30             #Dependencies
31              
32 3     3   138808 use parent 'Object::Meta::List';
  3         408  
  3         58  
33              
34 3     3   261 use Scalar::Util qw(blessed);
  3         6  
  3         242  
35 3     3   20 use Digest::MD5 qw(md5_hex);
  3         15  
  3         1511  
36              
37             =head1 DESCRIPTION
38              
39             C implements a class which indexes C
40             instances by their C field.
41              
42             Additionally a C meta data field will be created for indexation and lookup.
43              
44             The C meta data field is used to lookup entries.
45              
46             =cut
47              
48             #----------------------------------------------------------------------------
49             #Constructors
50              
51             =head1 METHODS
52              
53             =head2 Constructor
54              
55             =head3 new ( [ DATA ] )
56              
57             This is the constructor for a new C object.
58              
59             This overrides the C constructor to create the 'I' index
60             on the 'hash' field.
61              
62             B
63              
64             =over 4
65              
66             =item C
67              
68             The B which is passed in a hash like fashion,
69             using key and value pairs.
70              
71             =back
72              
73             See L|Object::Meta::List/"new ( [ DATA ] )">
74              
75             =cut
76              
77             sub new {
78 4   33 4 1 472774 my $class = ref( $_[0] ) || $_[0];
79              
80 4         35 my $self = $class->SUPER::new( @_[ 1 .. $#_ ] );
81              
82             #Index the Name Field
83 4         13 Object::Meta::List::setIndexField( $self, 'hash' );
84              
85 4         38 return $self;
86             }
87              
88             #----------------------------------------------------------------------------
89             #Administration Methods
90              
91             =head2 Administration Methods
92              
93             =head3 Add ( [ C | DATA ] )
94              
95             This works like C only that it handles
96             C instances.
97              
98             If no parameter is given it creates an empty instance of C
99             and adds it to the list
100              
101             B
102              
103             =over 4
104              
105             =item C
106              
107             An instance of C to be added to the list.
108              
109             =item C
110              
111             A hash with data to create an instance of C and add it to the list.
112              
113             =back
114              
115             B C - The object which was created or added.
116              
117             See L|Object::Meta::List/"Add ( [ C | DATA ] )">
118              
119             =cut
120              
121             sub Add {
122 6     6 1 17 my $self = $_[0];
123 6         10 my $mtaety = undef;
124              
125 6 50       12 if ( scalar(@_) > 1 ) {
126 6 50       19 if ( defined blessed $_[1] ) {
127 6         9 $mtaety = $_[1];
128             }
129             else #Parameter is not an Object
130             {
131             #Create the new MetaNameEntry Object from the given Parameters
132 0         0 $mtaety = Object::Meta::Named::->new( @_[ 1 .. $#_ ] );
133             }
134             }
135              
136 6 50 33     37 if ( defined $mtaety && !$mtaety->isa('Object::Meta::Named') ) {
137 0         0 $mtaety = undef;
138             }
139              
140 6 50       12 $mtaety = Object::Meta::Named::->new unless ( defined $mtaety );
141              
142             #Execute the Base Logic
143 6         16 Object::Meta::List::Add( $self, $mtaety );
144              
145 6         10 return $mtaety;
146             }
147              
148             #----------------------------------------------------------------------------
149             #Consultation Methods
150              
151             =head2 Consultation Methods
152              
153             =head3 getMetaObjectbyName ( NAME )
154              
155             This works like C only that it uses
156             the hash of the the C field to find the object.
157              
158             B
159              
160             =over 4
161              
162             =item C
163              
164             The string value for the C field of the object.
165              
166             =back
167              
168             B C - The object with the C field having the
169             value I.
170              
171             See L|Object::Meta::List/"getIdxMetaObject ( INDEX, NAME )">
172              
173             =cut
174              
175             sub getMetaObjectbyName {
176 2     2 1 6 my ( $self, $snm ) = @_;
177 2         4 my $mtaety = undef;
178              
179 2 50 33     15 if ( defined $snm
180             && $snm ne '' )
181             {
182 2         14 $mtaety = Object::Meta::List::getIdxMetaObject( $self, md5_hex($snm) );
183             }
184              
185 2         5 return $mtaety;
186             }
187              
188             return 1;