Meta/Named/List.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 70.3% 45 / 64 CC 9 SCAR 15.1
CC
9
Cov
73%
Add
7.7
getMetaObjectbyName
3.2
new
2.1
CRAP 4.5
« Meta/File/List.pm ↑ Summary Meta.pm »
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<Object::Meta::Named> instances by
23 their C<name> field.
24  
25 =cut
26  
27 package Object::Meta::Named::List;
28  
29 #----------------------------------------------------------------------------
30 #Dependencies
31  
32 3 ▶use parent 'Object::Meta::List';
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 =head1 DESCRIPTION
38  
39 C<Object::Meta::Named::List> implements a class which indexes C<Object::Meta::Named>
40 instances by their C<name> field.
41  
42 Additionally a C<hash> meta data field will be created for indexation and lookup.
43  
44 The C<hash> 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::Meta::Named::List> object.
58  
59 This overrides the C<Object::Meta> constructor to create the 'I<primary>' index
60 on the 'hash' field.
61  
62 B<Parameters:>
63  
64 =over 4
65  
66 =item C<DATA>
67  
68 The B<raw data> which is passed in a hash like fashion,
69 using key and value pairs.
70  
71 =back
72  
73 See L<Method C<Object::Meta::List::new()>|Object::Meta::List/"new ( [ DATA ] )">
74  
75 =cut
76  
77 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
78 4 ▶ my $class = ref( $_[0] ) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
79  
80 4 my $self = $class->SUPER::new( @_[ 1 .. $#_ ] );
81  
82 #Index the Name Field
83 4 Object::Meta::List::setIndexField( $self, 'hash' );
84  
85 4 return $self;
86 }
87  
88 #----------------------------------------------------------------------------
89 #Administration Methods
90  
91 =head2 Administration Methods
92  
93 =head3 Add ( [ C<Object::Meta::Named> | DATA ] )
94  
95 This works like C<Object::Meta::List::Add()> only that it handles
96 C<Object::Meta::Named> instances.
97  
98 If no parameter is given it creates an empty instance of C<Object::Meta::Named>
99 and adds it to the list
100  
101 B<Parameters:>
102  
103 =over 4
104  
105 =item C<Object::Meta::Named>
106  
107 An instance of C<Object::Meta::Named> to be added to the list.
108  
109 =item C<DATA>
110  
111 A hash with data to create an instance of C<Object::Meta::Named> and add it to the list.
112  
113 =back
114  
115 B<Returns:> C<Object::Meta::Named> - The object which was created or added.
116  
117 See L<Method C<Object::Meta::List::Add()>|Object::Meta::List/"Add ( [ C<Object::Meta> | DATA ] )">
118  
119 =cut
120  
121 6 ▶sub Add {
Subroutine Add: called CC=6 SCAR=20.5
Pod documented
122 6 my $self = $_[0];
123 6 my $mtaety = undef;
124  
125 6 ▶ if ( scalar(@_) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) 6 0 6
126 6 ▶ if ( defined blessed $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined builtin::blessed($_[1])) { } 6 0 6
127 6 $mtaety = $_[1];
128 }
129 else #Parameter is not an Object
130 {
131 #Create the new MetaNameEntry Object from the given Parameters
132 0 $mtaety = Object::Meta::Named::->new( @_[ 1 .. $#_ ] );
133 }
134 }
135  
136 6 ▶ if ( defined $mtaety && !$mtaety->isa('Object::Meta::Named') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mtaety and not $mtaety->isa("Object::Meta::Named")) 0 6 6
Condition33%1/3
defined $mtaety and not $mtaety->isa("Object::Meta::Named")
!ll&&!rl&&r
060
MC/DC0%0/2
defined $mtaety and not $mtaety->isa("Object::Meta::Named")
defined $mtaety not $mtaety->isa("Object::Meta::Named")
Truth table33%1/3
A and not(B)
A= defined $mtaetyB= not $mtaety->isa("Object::Meta::Named")
ABresult
0X0
100
111
137 0 $mtaety = undef;
138 }
139  
140 6 ▶ $mtaety = Object::Meta::Named::->new unless ( defined $mtaety );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mtaety 0 6 6
141  
142 #Execute the Base Logic
143 6 Object::Meta::List::Add( $self, $mtaety );
144  
145 6 return $mtaety;
146 }
147  
148 #----------------------------------------------------------------------------
149 #Consultation Methods
150  
151 =head2 Consultation Methods
152  
153 =head3 getMetaObjectbyName ( NAME )
154  
155 This works like C<Object::Meta::List::getIdxMetaObject()> only that it uses
156 the hash of the the C<name> field to find the object.
157  
158 B<Parameters:>
159  
160 =over 4
161  
162 =item C<NAME>
163  
164 The string value for the C<name> field of the object.
165  
166 =back
167  
168 B<Returns:> C<Object::Meta::Named> - The object with the C<name> field having the
169 value I<NAME>.
170  
171 See L<Method C<Object::Meta::List::getIdxMetaObject()>|Object::Meta::List/"getIdxMetaObject ( INDEX, NAME )">
172  
173 =cut
174  
175 2 ▶sub getMetaObjectbyName {
Subroutine getMetaObjectbyName: called CC=3 SCAR=11.8
Pod documented
176 2 my ( $self, $snm ) = @_;
177 2 my $mtaety = undef;
178  
179 2 ▶ if ( defined $snm
Branch: 1 branch
BranchTrueFalseTotal
if (defined $snm and $snm ne "") 2 0 2
Condition33%1/3
defined $snm and $snm ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $snm and $snm ne ""
defined $snm $snm ne ""
Truth table33%1/3
A and B
A= defined $snmB= $snm ne ""
ABresult
0X0
100
111
180 && $snm ne '' )
181 {
182 2 $mtaety = Object::Meta::List::getIdxMetaObject( $self, md5_hex($snm) );
183 }
184  
185 2 return $mtaety;
186 }
187  
188 3 return 1;
« Meta/File/List.pm ↑ Summary Meta.pm »