File Coverage

lib/Object/Meta/List.pm
Criterion Covered Total %
statement 195 316 61.7
branch 77 198 38.8
condition 29 109 26.6
subroutine 20 22 90.9
pod 7 15 46.6
total 328 660 49.7


line stmt bran cond sub pod time code
1             #
2             # @author Bodo (Hugo) Barwich
3             # @version 2025-10-21
4             # @package Object::Meta
5             # @subpackage Object/Meta/List.pm
6              
7             # This Module defines Classes to manage Data in an indexed List
8             #
9             #---------------------------------
10             # Requirements:
11             # - The Perl Package "libconst-fast-perl" must be installed
12             #
13             #---------------------------------
14             # Features:
15             # - Numerical Key Values in Object::Meta::List
16             # - Adding a Object::Meta Object to the Object::Meta::List by the Index Value
17             #
18              
19             #==============================================================================
20             # The Object::Meta::List Package
21              
22             =head1 NAME
23              
24             Object::Meta::List - Library to access C objects by B
25             and by insertion order.
26              
27             C enherits from C the capability to store Meta Data
28             which is used to create autogenerated object indices in-memory.
29              
30             =cut
31              
32             package Object::Meta::List;
33              
34             #----------------------------------------------------------------------------
35             #Dependencies
36              
37 4     4   167290 use parent 'Object::Meta';
  4         387  
  4         42  
38              
39 4     4   282 use Scalar::Util qw(blessed);
  4         8  
  4         336  
40              
41 4     4   27 use constant LIST_ENTRIES => 2;
  4         14  
  4         277  
42 4     4   23 use constant LIST_ENTRIES_INDEXED => 3;
  4         8  
  4         295  
43              
44 4     4   31 use constant PRIMARY_INDEXNAME => 'primary';
  4         9  
  4         19875  
45              
46             #----------------------------------------------------------------------------
47             #Constructors
48              
49             =head1 METHODS
50              
51             =head2 Constructor
52              
53             =head3 new ( [ DATA ] )
54              
55             This is the constructor for a new C object.
56              
57             Since C is also a C it can also hold meta data.
58              
59             B
60              
61             =over 4
62              
63             =item C
64              
65             The B which is passed in a hash like fashion, using key and value pairs.
66             This is passed to the inherited C constructor.
67              
68             =back
69              
70             =cut
71              
72             sub new {
73 13   33 13 1 304095 my $class = ref( $_[0] ) || $_[0];
74              
75 13         114 my $self = $class->SUPER::new( @_[ 1 .. $#_ ] );
76              
77             #Create the additional Entry Lists
78 13         49 $self->[LIST_ENTRIES] = ();
79 13         37 $self->[LIST_ENTRIES_INDEXED] = ();
80              
81             #Give the Object back
82 13         43 return $self;
83             }
84              
85             sub DESTROY {
86 13     13   21262 my $self = $_[0];
87              
88             #Free the Entry Lists
89 13         48 $self->[LIST_ENTRIES] = ();
90 13         56 $self->[LIST_ENTRIES_INDEXED] = ();
91              
92             #Call Base Class Destructor
93 13         54 $self->SUPER::DESTROY;
94             }
95              
96             #----------------------------------------------------------------------------
97             #Administration Methods
98              
99             sub setIndexField {
100 9     9 1 30 my ( $self, $sindexname, $sindexfield ) = @_;
101              
102 9 50       35 unless ( defined $sindexfield ) {
103 9         15 $sindexfield = $sindexname;
104 9         17 $sindexname = PRIMARY_INDEXNAME;
105             }
106              
107             #print "'" . (caller(1))[3] . "' : Signal to '" . (caller(0))[3] . "'\n";
108             #print "" . (caller(0))[3] . " - idx nm: '$sindexname'; idx fld: '$sindexfield'\n";
109              
110 9 50 33     57 if ( defined $sindexfield
111             && $sindexfield ne "" )
112             {
113 9         53 $self->createIndex(
114             ( 'indexname' => $sindexname, 'checkfield' => $sindexfield ) );
115             }
116             }
117              
118             =head2 Administration Methods
119              
120             =head3 Add ( [ C | DATA ] )
121              
122             This adds new items to the list.
123              
124             If no parameter is given it creates an empty instance of C
125             and adds it to the list
126              
127             B
128              
129             =over 4
130              
131             =item C
132              
133             An instance of C to be added to the list.
134              
135             =item C
136              
137             A hash with data to create an instance of C and add it to the list.
138              
139             =back
140              
141             B C - The object which was created or added.
142              
143             See L|Object::Meta/"new ( [ DATA ] )">
144              
145             =cut
146              
147             sub Add {
148 30     30 1 778 my $self = $_[0];
149 30         50 my $mtaety = undef;
150              
151 30 50       76 if ( scalar(@_) > 1 ) {
152 30 100       79 if ( defined blessed $_[1] ) {
153 15         24 $mtaety = $_[1];
154             }
155             else #Parameter is not an Object
156             {
157 15 100       33 if ( scalar(@_) > 2 ) {
158              
159             #Create the new Object::Meta from the given Parameters
160 6         31 $mtaety = Object::Meta::->new( @_[ 1 .. $#_ ] );
161             }
162             else #A Single Scalar Parameter
163             {
164             #Create the new Object::Meta with the Index Value
165 9         52 $mtaety = Object::Meta::->new( $self->getIndexField, $_[1] );
166             }
167             }
168             }
169              
170 30 50       70 if ( defined $mtaety ) {
171 30 50       208 unless ( $mtaety->isa('Object::Meta') ) {
172 0         0 $mtaety = undef;
173             }
174             }
175              
176 30 50       71 $mtaety = Object::Meta::->new unless ( defined $mtaety );
177              
178 30 50 33     138 if ( defined $mtaety
179             && $mtaety->isa("Object::Meta") )
180             {
181 30         80 my $ietycnt = $self->getMetaObjectCount;
182              
183 30         52 push @{ $self->[LIST_ENTRIES] }, ($mtaety);
  30         87  
184              
185 30 50       82 $ietycnt = 0 if ( $ietycnt < 0 );
186              
187             #Update the MetaEntry Count
188 30         88 $self->setMeta( "entrycount", $ietycnt + 1 );
189              
190             #Add the the MetaEntry Object to the Index Lists
191 30         93 $self->_indexMetaObject($mtaety);
192              
193             } #if(defined $mtaety && $mtaety->isa("Object::Meta"))
194              
195             #Give the added Object::Meta back
196 30         72 return $mtaety;
197             }
198              
199             sub _indexMetaObject {
200 30     30   61 my ( $self, $mtaety ) = @_;
201              
202 30 50 33     172 if ( defined $mtaety
203             && $mtaety->isa('Object::Meta') )
204             {
205 30         85 my $hshidxcnfs = $self->getMeta( 'indexconfiguration', {} );
206 30         59 my $hshidxcnf = undef;
207 30         43 my $iupdidxcnf = 0;
208              
209 30         45 my $slstmnidxvl = '';
210 30         39 my $slstidxvl = '';
211 30         39 my $slstchkvl = '';
212              
213 30         40 foreach ( keys %{$hshidxcnfs} ) {
  30         81  
214 36         64 $hshidxcnf = $hshidxcnfs->{$_};
215              
216 36 50       67 if ( defined $hshidxcnf ) {
217             $mtaety->setIndexField( $hshidxcnf->{'indexfield'} )
218 36 100       133 if ( $hshidxcnf->{'indexname'} eq PRIMARY_INDEXNAME );
219              
220             $slstmnidxvl =
221 36         107 $mtaety->get( $hshidxcnf->{'indexfield'}, undef );
222             $slstchkvl = $mtaety->get( $hshidxcnf->{'checkfield'},
223 36         94 undef, $hshidxcnf->{'meta'} );
224 36         58 $slstidxvl = '';
225              
226 36 100 66     131 if ( defined $slstchkvl
227             && $slstchkvl ne '' )
228             {
229 32 100       71 if ( $hshidxcnf->{'checkvalue'} ne '' ) {
230             $slstidxvl = $slstmnidxvl
231 8 100 66     41 if ( "$slstchkvl" eq $hshidxcnf->{'checkvalue'} . ''
232             && defined $slstmnidxvl );
233              
234             }
235             else #Its not a by Value Index
236             {
237 24         33 $slstidxvl = $slstmnidxvl;
238             } #if($hshidxcnf->{"checkvalue"} ne "")
239             } #if(defined $slstchkvl && $slstchkvl ne "")
240              
241             #print "idx nm: '$hshidxcnf->{'indexname'}'; chk fld: '$hshidxcnf->{'checkfield'}'; fld vl: '$slstchkvl'; idx vl: '$slstidxvl'\n";
242              
243 36 100       95 if ( $slstidxvl ne '' ) {
244             $self->[LIST_ENTRIES_INDEXED]{ $hshidxcnf->{'indexname'} }
245             = ()
246             unless (
247             defined $self->[LIST_ENTRIES_INDEXED]
248 30 100       112 { $hshidxcnf->{'indexname'} } );
249              
250 30 50       91 unless (
251             defined $self->[LIST_ENTRIES_INDEXED]
252             { $hshidxcnf->{'indexname'} }{$slstidxvl} )
253             {
254             $self->[LIST_ENTRIES_INDEXED]
255 30         71 { $hshidxcnf->{'indexname'} }{$slstidxvl} = $mtaety;
256              
257             #Count the Entries
258 30 100 66     125 if ( defined $hshidxcnf->{'count'}
259             && $hshidxcnf->{'count'} > 0 )
260             {
261 18         31 $hshidxcnf->{'count'}++;
262             }
263             else {
264 12         32 $hshidxcnf->{'count'} = 1;
265             }
266              
267 30 100       83 $iupdidxcnf = 1 unless ($iupdidxcnf);
268              
269             } #unless(defined $self->[LIST_ENTRIES_INDEXED]{$hshidxcnf->{'indexname'}}{$slstidxvl})
270             } #if($sidxvl ne "")
271              
272             } #if(defined $hshidxcnf)
273             } #foreach (keys %{$hshidxcnfs})
274              
275 30 100       82 if ($iupdidxcnf) {
276 24         73 $self->setMeta( 'indexconfiguration', $hshidxcnfs );
277             } #if($iupdidxcnf)
278             } #if(defined $mtaety && $mtaety->isa('Object::Meta'))
279             }
280              
281             sub createIndex {
282 14     14 0 28 my $self = shift;
283              
284             #Take the Method Parameters and set Default Values
285 14         117 my %hshprms = (
286             "indexname" => "",
287             "indexfield" => "",
288             "checkfield" => "",
289             "checkvalue" => "",
290             "meta" => 0,
291             "subset" => 0,
292             "rebuild" => 0,
293             @_
294             );
295              
296 14 50       58 if ( $hshprms{"checkfield"} ne "" ) {
297 14         67 my $hshidxcnfs = $self->getMeta( "indexconfiguration", {} );
298 14         36 my $sidxnm = $hshprms{"indexname"};
299 14         20 my $iupdidxcnf = 0;
300              
301 14 50 33     65 unless ( defined $sidxnm
302             && $sidxnm ne "" )
303             {
304 0         0 $sidxnm = $hshprms{"checkfield"};
305              
306             $sidxnm .= "_" . $hshprms{"checkvalue"}
307             if ( defined $hshprms{"checkvalue"}
308 0 0 0     0 && $hshprms{"checkvalue"} ne "" );
309              
310             } #unless(defined $sidxnm && $sidxnm ne "")
311              
312 14 50 33     79 unless ( defined $hshprms{"indexfield"}
313             && $hshprms{"indexfield"} ne "" )
314             {
315 14 100 66     89 if ( defined $hshprms{"checkvalue"}
316             && $hshprms{"checkvalue"} ne "" )
317             {
318 4         36 $hshprms{"indexfield"} = $self->getIndexField;
319             }
320             else {
321 10         62 $hshprms{"indexfield"} = $hshprms{"checkfield"};
322             }
323              
324 14         25 $iupdidxcnf = 1;
325             } #unless(defined $hshprms{"indexfield"} && $hshprms{"indexfield"} ne "")
326              
327             $hshprms{"subset"} = 1
328             if ( defined $hshprms{"checkvalue"}
329 14 100 66     90 && $hshprms{"checkvalue"} ne "" );
330              
331 14 50       31 %{$hshidxcnfs} = () unless ( defined $hshidxcnfs );
  0         0  
332              
333 14 50       34 if ( defined $hshidxcnfs->{$sidxnm} ) {
334 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"name"}
335             && $hshidxcnfs->{$sidxnm}{"name"} eq $sidxnm )
336             {
337 0         0 $hshidxcnfs->{$sidxnm}{"name"} = $sidxnm;
338 0         0 $iupdidxcnf = 1;
339             }
340              
341 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"indexfield"}
342             && $hshidxcnfs->{$sidxnm}{"indexfield"} eq
343             $hshprms{"indexfield"} )
344             {
345 0         0 $hshidxcnfs->{$sidxnm}{"indexfield"} = $hshprms{"indexfield"};
346 0         0 $iupdidxcnf = 1;
347             }
348              
349 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"checkfield"}
350             && $hshidxcnfs->{$sidxnm}{"checkfield"} eq
351             $hshprms{"checkfield"} )
352             {
353 0         0 $hshidxcnfs->{$sidxnm}{"checkfield"} = $hshprms{"checkfield"};
354 0         0 $iupdidxcnf = 1;
355             }
356              
357 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"checkvalue"}
358             && $hshidxcnfs->{$sidxnm}{"checkvalue"} eq
359             $hshprms{"checkvalue"} )
360             {
361 0         0 $hshidxcnfs->{$sidxnm}{"checkvalue"} = $hshprms{"checkvalue"};
362 0         0 $iupdidxcnf = 1;
363             }
364              
365 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"meta"}
366             && $hshidxcnfs->{$sidxnm}{"meta"} == $hshprms{"meta"} )
367             {
368 0         0 $hshidxcnfs->{$sidxnm}{"meta"} = $hshprms{"meta"};
369 0         0 $iupdidxcnf = 1;
370             }
371              
372 0 0 0     0 unless ( defined $hshidxcnfs->{$sidxnm}{"subset"}
373             && $hshidxcnfs->{$sidxnm}{"subset"} == $hshprms{"subset"} )
374             {
375 0         0 $hshidxcnfs->{$sidxnm}{"subset"} = $hshprms{"subset"};
376 0         0 $iupdidxcnf = 1;
377             }
378              
379 0 0       0 unless ( defined $hshidxcnfs->{$sidxnm}{"count"} ) {
380 0         0 $hshidxcnfs->{$sidxnm}{"count"} = 0;
381 0         0 $iupdidxcnf = 1;
382             }
383             }
384             else #The Index Definition does not exist yet
385             {
386 14         23 $iupdidxcnf = 1;
387              
388 14         83 $hshidxcnfs->{$sidxnm}{"indexname"} = $sidxnm;
389 14         36 $hshidxcnfs->{$sidxnm}{"indexfield"} = $hshprms{"indexfield"};
390 14         27 $hshidxcnfs->{$sidxnm}{"checkfield"} = $hshprms{"checkfield"};
391 14         33 $hshidxcnfs->{$sidxnm}{"checkvalue"} = $hshprms{"checkvalue"};
392 14         31 $hshidxcnfs->{$sidxnm}{"meta"} = $hshprms{"meta"};
393 14         40 $hshidxcnfs->{$sidxnm}{"subset"} = $hshprms{"subset"};
394 14         30 $hshidxcnfs->{$sidxnm}{"count"} = 0;
395             } #if(defined $hshidxcnfs->{$sidxnm})
396              
397 14 50       45 if ($iupdidxcnf) {
398 14         65 $self->setMeta( "indexconfiguration", $hshidxcnfs );
399              
400 14         32 $hshprms{"rebuild"} = 1;
401             } #if($iupdidxcnf)
402              
403             #Build the Index and fill it with MetaEntry Objects
404 14         87 $self->buildIndex( $sidxnm, $hshprms{"rebuild"} );
405              
406             } #if($hshprms{"checkfield"} ne "")
407             }
408              
409             sub buildIndex {
410 14     14 0 23 my $self = shift;
411 14         26 my $sindexname = shift;
412 14   50     33 my $irebuild = shift || 0;
413              
414 14 50       37 $sindexname = PRIMARY_INDEXNAME unless ( defined $sindexname );
415              
416             #print "" .(caller(0))[3] . " - idx: '$sindexname', rbd: '$irebuild'. go ...\n";
417              
418 14 50 33     64 if ( defined $sindexname
419             && $sindexname ne "" )
420             {
421 14         45 my $hshidxcnfs = $self->getMeta( "indexconfiguration", {} );
422 14         31 my $hshidxcnf = undef;
423 14         36 my $sidxvl = "";
424 14         21 my $iidxcnt = -1;
425 14         20 my $iupdidxcnf = 0;
426              
427             $hshidxcnf = $hshidxcnfs->{$sindexname}
428 14 50       59 if ( defined $hshidxcnfs->{$sindexname} );
429              
430 14 50 33     76 if ( defined $hshidxcnf
431             && defined $hshidxcnf->{"checkfield"} )
432             {
433 14 50 33     74 unless ( defined $hshidxcnf->{"indexfield"}
434             && $hshidxcnf->{"indexfield"} ne "" )
435             {
436 0         0 $hshidxcnf->{"indexfield"} = $hshidxcnf->{"checkfield"};
437              
438 0         0 $iupdidxcnf = 1;
439             }
440              
441             $iidxcnt = $hshidxcnf->{"count"}
442 14 50       52 if ( defined $hshidxcnf->{"count"} );
443              
444             } #if(defined $hshidxcnf && defined $hshidxcnf->{"checkfield"})
445              
446             #print "idx fld: '$sidxfld'; chk fld: '$schkfld'; chk vl: '$schkvl'"
447             # . "; mta: '$imta'; set: '$isbset'\n";
448              
449 14 50 33     108 if ( defined $hshidxcnf
      33        
450             && defined $hshidxcnf->{"checkfield"}
451             && $hshidxcnf->{"checkfield"} ne "" )
452             {
453 14         49 my $ietycnt = $self->getMetaObjectCount;
454              
455             #Check the Index when the List was updated or when the Index was changed
456 14         32 my $ibld = $iupdidxcnf;
457              
458 14 50       44 if ($irebuild) {
459 14 50       40 if ( defined $self->[LIST_ENTRIES_INDEXED]{$sindexname} ) {
460 0         0 $self->[LIST_ENTRIES_INDEXED]{$sindexname} = ();
461             } #if(defined $self->{"_list_entries_indexed"}{$sindexname})
462              
463 14         18 $iidxcnt = 0;
464 14         34 $iupdidxcnf = 1;
465              
466             #Check the Index
467 14         21 $ibld = 1;
468             } #if($irebuild)
469              
470 14 50       35 if ( defined $self->[LIST_ENTRIES_INDEXED]{$sindexname} ) {
471              
472             #Check the Index
473 0 0       0 $ibld = 1 if ( $iidxcnt < 0 );
474             }
475             else #The Index still doesn't exist
476             {
477 14         36 $self->[LIST_ENTRIES_INDEXED]{$sindexname} = ();
478              
479             #Check the Index
480 14         22 $ibld = 1;
481             } #if(defined $self->{"_list_entries_indexed"}{$sindexname})
482              
483 14 50       38 if ( $ietycnt > 0 ) {
484 0 0       0 unless ( $hshidxcnf->{"subset"} ) {
485 0 0 0     0 $ibld = 1 if ( $ibld || $ietycnt != $iidxcnt );
486             } #unless($hshidxcnf->{"subset"})
487             }
488             else #There aren't any Objects in the List
489             {
490 14         23 $ibld = 0;
491             } #if($ietycnt > 0)
492              
493             #print "ety cnt: '$ietycnt'; idx ety cnt: '$iidxcnt'; bld: '$ibld'\n";
494              
495 14 50       35 if ($ibld) {
496 0         0 my $ety = undef;
497 0         0 my $sidxvl = "";
498 0         0 my $slstetyidxvl = "";
499 0         0 my $slstchkvl = undef;
500 0         0 my $iety = -1;
501              
502 0         0 $iidxcnt = 0;
503              
504 0         0 for ( $iety = 0 ; $iety < $ietycnt ; $iety++ ) {
505 0         0 $ety = $self->[LIST_ENTRIES][$iety];
506 0         0 $sidxvl = "";
507              
508 0 0       0 if ( defined $ety ) {
509             $slstetyidxvl =
510 0         0 $ety->get( $hshidxcnf->{"indexfield"}, undef );
511             $slstchkvl = $ety->get( $hshidxcnf->{"checkfield"},
512 0         0 undef, $hshidxcnf->{"meta"} );
513              
514 0 0 0     0 if ( defined $slstchkvl
515             && $slstchkvl ne "" )
516             {
517 0 0       0 if ( $hshidxcnf->{"checkvalue"} ne "" ) {
518             $sidxvl = $slstetyidxvl
519             if (
520 0 0 0     0 "$slstchkvl" eq $hshidxcnf->{"checkvalue"}
521             . ""
522             && defined $slstetyidxvl );
523              
524             }
525             else #Its not a by Value Index
526             {
527 0         0 $sidxvl = $slstetyidxvl;
528             } #if($sfldvl ne "")
529             } #if(defined $slstchkvl && $slstchkvl ne "")
530              
531             #print "idx nm: '$sindexname'; chk fld: '$schkfld'; fld vl: '$slstchkvl'; idx vl: '$sidxvl'\n";
532              
533 0 0       0 if ( $sidxvl ne "" ) {
534 0 0       0 unless (
535             defined $self->[LIST_ENTRIES_INDEXED]
536             {$sindexname}{$sidxvl} )
537             {
538             $self->[LIST_ENTRIES_INDEXED]{$sindexname}
539 0         0 {$sidxvl} = $ety;
540              
541             #Count the Entries
542 0         0 $iidxcnt++;
543              
544 0 0       0 $iupdidxcnf = 1 unless ($iupdidxcnf);
545              
546             } #unless(defined $self->[LIST_ENTRIES_INDEXED]{$sindexname}{$sidxvl})
547             } #if($sidxvl ne "")
548             } #if(defined $ety)
549             } #for($iety = 0; $iety < $ietycnt; $iety++)
550             } #if($ibld)
551             } #if(defined $hshidxcnf && defined $hshidxcnf->{"checkfield"}
552             # && $hshidxcnf->{"checkfield"} ne "")
553              
554 14 50       30 if ($iupdidxcnf) {
555 14         55 $hshidxcnfs->{$sindexname}{"count"} = $iidxcnt;
556              
557 14         76 $self->setMeta( "indexconfiguration", $hshidxcnfs );
558             } #if($iupdidxcnf)
559             } #if(defined $sindexname && $sindexname ne "")
560              
561             }
562              
563             sub buildIndexAll {
564 0     0 0 0 my $self = shift;
565 0   0     0 my $irebuild = shift || 0;
566              
567 0         0 my $ietycnt = $self->getMetaObjectCount;
568              
569 0         0 my $hshidxcnfs = $self->getMeta( "indexconfiguration", {} );
570 0         0 my $hshidxcnf = undef;
571 0         0 my $sidxnm = "";
572 0         0 my $iidxcnt = -1;
573              
574 0         0 my $ibld = 0;
575              
576 0 0       0 if ( scalar( keys %$hshidxcnfs ) > 0 ) {
577 0         0 foreach $sidxnm ( keys %{$hshidxcnfs} ) {
  0         0  
578 0         0 $hshidxcnf = $hshidxcnfs->{$sidxnm};
579              
580 0 0       0 if ( defined $hshidxcnf ) {
581 0 0 0     0 unless ( defined $hshidxcnf->{"indexfield"}
582             && $hshidxcnf->{"indexfield"} ne "" )
583             {
584 0         0 $hshidxcnf->{"indexfield"} = $hshidxcnf->{"checkfield"};
585              
586 0         0 $ibld = 1;
587             } #unless(defined $hshidxcnf->{"indexfield"} && $hshidxcnf->{"indexfield"} ne "")
588              
589             $iidxcnt = $hshidxcnf->{"count"}
590 0 0       0 if ( defined $hshidxcnf->{"count"} );
591              
592             } #if(defined $hshidxcnf)
593              
594 0 0       0 if ($irebuild) {
595 0 0       0 if ( defined $self->[LIST_ENTRIES_INDEXED]{$sidxnm} ) {
596 0         0 $self->[LIST_ENTRIES_INDEXED]{$sidxnm} = ();
597             } #if(defined $self->[LIST_ENTRIES_INDEXED]{$sidxnm})
598              
599 0         0 $hshidxcnf->{"count"} = 0;
600              
601             #Check the Index
602 0         0 $ibld = 1;
603             } #if($irebuild)
604              
605 0 0       0 if ( defined $self->[LIST_ENTRIES_INDEXED]{$sidxnm} ) {
606              
607             #Check the Index
608 0 0       0 $ibld = 1 if ( $iidxcnt < 0 );
609             }
610             else #The Index still doesn't exist
611             {
612 0         0 $self->[LIST_ENTRIES_INDEXED]{$sidxnm} = ();
613              
614             #Check the Index
615 0         0 $ibld = 1;
616             } #if(defined $self->{"_list_entries_indexed"}{$sidxnm})
617              
618 0 0       0 if ( $ietycnt > 0 ) {
619 0 0       0 unless ( $hshidxcnf->{"subset"} ) {
620 0 0 0     0 $ibld = 1 if ( $ibld || $ietycnt != $iidxcnt );
621             } #unless($hshidxcnf->{"subset"})
622             } #if($ietycnt > 0)
623              
624             #print "idx nm: '$sidxnm'; idx ety cnt: '$iidxcnt'; bld: '$ibld'\n";
625              
626             } #foreach $sidxnm (keys %{$hshidxcnfs})
627              
628             } #if(scalar(keys %$hshidxcnfs) > 0)
629              
630             #print "ety cnt: '$ietycnt'; bld: '$ibld'\n";
631              
632 0 0       0 if ($ibld) {
633 0         0 my $ety = undef;
634 0         0 my $sidxvl = "";
635 0         0 my $slstetyidxvl = "";
636 0         0 my $slstchkvl = undef;
637 0         0 my $iety = -1;
638              
639 0         0 foreach $sidxnm ( keys %{$hshidxcnfs} ) {
  0         0  
640 0         0 $hshidxcnfs->{$sidxnm}{"count"} = 0;
641             }
642              
643 0         0 for ( $iety = 0 ; $iety < $ietycnt ; $iety++ ) {
644 0         0 $ety = $self->[LIST_ENTRIES][$iety];
645 0         0 $sidxvl = "";
646              
647 0 0       0 if ( defined $ety ) {
648 0         0 foreach $sidxnm ( keys %{$hshidxcnfs} ) {
  0         0  
649 0         0 $hshidxcnf = $hshidxcnfs->{$sidxnm};
650              
651             $slstetyidxvl =
652 0         0 $ety->get( $hshidxcnf->{"indexfield"}, undef );
653             $slstchkvl = $ety->get( $hshidxcnf->{"checkfield"},
654 0         0 undef, $hshidxcnf->{"meta"} );
655 0         0 $sidxvl = '';
656              
657 0 0 0     0 if ( defined $slstchkvl
658             && $slstchkvl ne "" )
659             {
660 0 0       0 if ( $hshidxcnf->{"checkvalue"} ne "" ) {
661             $sidxvl = $slstetyidxvl
662             if (
663 0 0 0     0 "$slstchkvl" eq $hshidxcnf->{"checkvalue"} . ""
664             && defined $slstetyidxvl );
665              
666             }
667             else #Its not a by Value Index
668             {
669 0         0 $sidxvl = $slstetyidxvl;
670             } #if($sfldvl ne "")
671             } #if(defined $slstchkvl && $slstchkvl ne "")
672              
673             #print "idx nm: '$sindexname'; chk fld: '$schkfld'; fld vl: '$slstchkvl'; idx vl: '$sidxvl'\n";
674              
675 0 0       0 if ( $sidxvl ne "" ) {
676 0 0       0 unless (
677             defined $self->[LIST_ENTRIES_INDEXED]{$sidxnm}
678             {$sidxvl} )
679             {
680 0         0 $self->[LIST_ENTRIES_INDEXED]{$sidxnm}{$sidxvl} =
681             $ety;
682              
683             #Count the Entries
684 0         0 $hshidxcnf->{"count"}++;
685              
686 0 0       0 $iupdidxcnf = 1 unless ($iupdidxcnf);
687              
688             } #unless(defined $self->[LIST_ENTRIES_INDEXED]{$sindexname}{$sidxvl})
689             } #if($sidxvl ne "")
690             } #foreach $sidxnm (keys %{$hshidxcnfs})
691             } #if(defined $ety)
692             } #for($iety = 0; $iety < $ietycnt; $iety++)
693             } #if($ibld)
694              
695 0 0       0 if ($iupdidxcnf) {
696 0         0 $self->setMeta( "indexconfiguration", $hshidxcnfs );
697             } #if($iupdidxcnf)
698             }
699              
700             sub Clear {
701 1     1 1 3 my $self = $_[0];
702 1         5 my $hshidxcnfs = $self->getMeta( "indexconfiguration", {} );
703              
704             #Execute the Base Class Logic
705 1         10 $self->SUPER::Clear;
706              
707             #Save the Index Configuration
708 1         4 $self->setMeta( "indexconfiguration", $hshidxcnfs );
709              
710             #Clear the Object List too
711 1         4 $self->clearList;
712             }
713              
714             sub clearList {
715 1     1 0 2 my $self = $_[0];
716 1         4 my $hshidxcnfs = $self->getMeta( 'indexconfiguration', {} );
717              
718             #Clear the Entry Lists
719 1         4 $self->[LIST_ENTRIES] = ();
720 1         5 $self->[LIST_ENTRIES_INDEXED] = ();
721              
722 1         3 foreach ( keys %{$hshidxcnfs} ) {
  1         4  
723 1         4 $hshidxcnfs->{$_}{"count"} = 0;
724             }
725             }
726              
727             sub clearLists {
728 0     0 0 0 goto &clearList;
729             }
730              
731             #----------------------------------------------------------------------------
732             #Consultation Methods
733              
734             =head2 Consultation Methods
735              
736             =head3 getIndexField ( [ INDEX ] )
737              
738             This method returns the name of the field that is used to index the instances
739             by the index C.
740              
741             B
742              
743             =over 4
744              
745             =item C
746              
747             Name of the index. If not given the predefined C index
748             with name "I" is used.
749              
750             =back
751              
752             B string - The object with the indexed field having the
753             value I.
754              
755             =cut
756              
757             sub getIndexField {
758 24     24 1 2430 my ( $self, $sindexname ) = @_;
759 24         45 my $sindexfield = '';
760 24         71 my $hshidxcnfs = $self->getMeta( 'indexconfiguration', {} );
761              
762 24 50       68 $sindexname = PRIMARY_INDEXNAME unless ( defined $sindexname );
763              
764 24 50       60 if ( defined $hshidxcnfs->{$sindexname} ) {
765             $sindexfield = $hshidxcnfs->{$sindexname}{"indexfield"}
766 24 50       123 if ( defined $hshidxcnfs->{$sindexname}{"indexfield"} );
767              
768             }
769              
770 24         133 return $sindexfield;
771             }
772              
773             sub getMetaObject {
774 16     16 0 115 my ( $self, $iindex ) = @_[ 0 .. 1 ];
775 16         35 my $rsety = undef;
776              
777 16 50       60 if ( defined $iindex ) {
778 16 50       133 if ( $iindex =~ /^\-?\d+$/ ) {
779 16 100 66     63 if ( $iindex > -1
780 16         83 && $iindex < scalar( @{ $self->[LIST_ENTRIES] } ) )
781             {
782 3         8 $rsety = $self->[LIST_ENTRIES][$iindex];
783             }
784             }
785             else #The Index Value is a Text
786             {
787             #For a Indexed Object Lookup there need to be more parameters
788 0         0 $rsety = $self->getIdxMetaObject( $iindex, @_[ 2 .. $#_ ] );
789             }
790             }
791              
792 16         1065 return $rsety;
793             }
794              
795             =head3 getIdxMetaObject ( INDEX, NAME )
796              
797             This uses the index of name C to find the C object to find
798             the instance.
799              
800             B
801              
802             =over 4
803              
804             =item C
805              
806             Name of the index.
807              
808             =item C
809              
810             The string value for field indexed with the index C of the object.
811              
812             =back
813              
814             B C - The object with the indexed field having the
815             value I.
816              
817             =cut
818              
819             sub getIdxMetaObject {
820 7     7 1 3375 my ( $self, $sindexname, $sindexvalue ) = @_;
821 7         17 my $rsety = undef;
822              
823 7 50       22 unless ( defined $sindexvalue ) {
824 7         13 $sindexvalue = $sindexname;
825 7         15 $sindexname = PRIMARY_INDEXNAME;
826             }
827              
828             #print "idx nm: '$sindexname'; idx vl: '$sindexvalue'\n";
829              
830 7 100 66     50 if ( $sindexname ne ''
831             && defined $self->[LIST_ENTRIES_INDEXED]{$sindexname} )
832             {
833             $rsety = $self->[LIST_ENTRIES_INDEXED]{$sindexname}{$sindexvalue}
834             if (
835 6 50       22 defined $self->[LIST_ENTRIES_INDEXED]{$sindexname}{$sindexvalue} );
836              
837             }
838              
839 7         21 return $rsety;
840             }
841              
842             =head3 getMetaObjectCount
843              
844             This Method gives the Count of C objects back that are hold in the List.
845             If the B C is not set it will be created.
846              
847             B integer - The Count of C objects in the List
848              
849             =cut
850              
851             sub getMetaObjectCount {
852 64     64 1 13110 my $self = $_[0];
853 64         214 my $irscnt = $self->getMeta( 'entrycount', -1 );
854              
855 64 100       171 if ( $irscnt < 0 ) {
856 14 50       39 if ( defined $self->[LIST_ENTRIES] ) {
857 0         0 $irscnt = scalar( @{ $self->[LIST_ENTRIES] } );
  0         0  
858             }
859             else {
860 14         21 $irscnt = 0;
861             }
862              
863 14         80 $self->setMeta( 'entrycount', $irscnt );
864             } #if($irscnt < 0)
865              
866 64         174 return $irscnt;
867             }
868              
869             sub getIdxMetaObjectCount {
870 13     13 0 64 my ( $self, $sindexname ) = @_;
871 13         25 my $irscnt = -1;
872              
873 13         44 my $hshidxcnfs = $self->getMeta( 'indexconfiguration', {} );
874              
875 13 100       43 $sindexname = PRIMARY_INDEXNAME unless ( defined $sindexname );
876              
877 13 50 33     81 if ( $sindexname ne ''
878             && defined $hshidxcnfs->{$sindexname} )
879             {
880 13         29 $irscnt = $hshidxcnfs->{$sindexname}{"count"};
881             }
882              
883 13 50 33     54 if ( $irscnt < 0
884             && defined $hshidxcnfs->{$sindexname} )
885             {
886 0         0 $irscnt = scalar( keys %{ $self->[LIST_ENTRIES_INDEXED]{$sindexname} } )
887 0 0       0 if ( defined $self->[LIST_ENTRIES_INDEXED]{$sindexname} );
888              
889 0 0       0 if ( $irscnt > 0 ) {
890 0         0 $hshidxcnfs->{$sindexname}{"count"} = $irscnt;
891              
892 0         0 $self->setMeta( "indexconfiguration", $hshidxcnfs );
893             } #if($irscnt > 0)
894             } #if($irscnt < 0 && defined $hshidxcnfs->{$sindexname})
895              
896 13         62 return $irscnt;
897             }
898              
899             sub getIdxValueArray {
900 2     2 0 2182 my $self = shift;
901 2         5 my $sindexname = shift;
902 2         7 my @arrrs = undef;
903              
904 2 100       9 $sindexname = PRIMARY_INDEXNAME unless ( defined $sindexname );
905              
906 2 50 33     16 if ( $sindexname ne ""
907             && defined $self->[LIST_ENTRIES_INDEXED]{$sindexname} )
908             {
909 2         4 @arrrs = keys %{ $self->[LIST_ENTRIES_INDEXED]{$sindexname} };
  2         11  
910             }
911             else {
912 0         0 @arrrs = ();
913             } #if($sindexname ne "" && defined $self->[LIST_ENTRIES_INDEXED]{$sindexname})
914              
915 2         10 return (@arrrs);
916             }
917              
918             return 1;