WE/DB/ObjBase.pm

filter: Statementstmt 6.7% 14 / 207 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 16.6% 4 / 24 Podpod 94.4% 17 / 18 totaltotal 9.8% 35 / 357 CC 54 SCAR 34.8
CC
54
Cov
5%
pathobjects_with_cache
90.0
is_locked
72.0
walk_prepostorder
42.0
CRAP 32.6
« WE/Util/AtJobManager.pm ↑ Summary WE/DB/Content.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: ObjBase.pm,v 1.16 2004/02/19 22:26:53 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2002 Slaven Rezic. All rights reserved.
8 # This package is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
13 #
14  
15 =head1 NAME
16  
17 WE::DB::ObjBase - base class for WE_Framework object databases
18  
19 =head1 SYNOPSIS
20  
21 use base qw(WE::DB::ObjBase);
22  
23 =head1 DESCRIPTION
24  
25 =cut
26  
27 package WE::DB::ObjBase;
28 15 ▶use base qw(WE::DB::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 15 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 15 $VERSION = sprintf("%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/);
33  
34 15 ▶use WE::Util::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =head2 METHODS
37  
38 Please see also L<WE::DB::Base> for inherited methods.
39  
40 =over
41  
42 =cut
43  
44 =item children($object_id)
45  
46 Like children_ids, but return objects.
47  
48 =cut
49  
50 0 ▶sub children {
Subroutine children: not called CC=2 SCAR=17.9
Pod documented
51 0 my($self, $obj_id) = @_;
52 map {
53 0 my $o = $self->get_object($_);
54 0 ▶ if (!$o) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o) { } 0 0 0
55 0 my $obj_id = $obj_id;
56 0 my $child_id = $_;
57 0 $self->idify_params($obj_id, $child_id);
58 0 warn "Inconsistency in children method call for objid=$obj_id detected: child with objid=$child_id non-existent. Consider to run we_fsck. Error";
59 0 ();
60 } else {
61 0 $o;
62 }
63 } $self->children_ids($obj_id);
64 }
65  
66 =item parents($object_id)
67  
68 Like parent_ids, but return parent objects instead.
69  
70 =cut
71  
72 0 ▶sub parents {
Subroutine parents: not called CC=2 SCAR=17.9
Pod documented
73 0 my($self, $obj_id) = @_;
74 map {
75 0 my $o = $self->get_object($_);
76 0 ▶ if (!$o) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o) { } 0 0 0
77 0 warn "Inconsistency in parents($obj_id) detected";
78 0 ();
79 } else {
80 0 $o;
81 }
82 } $self->parent_ids($obj_id);
83 }
84  
85 =item versions($object_id)
86  
87 Like version_ids, but return version objects instead.
88  
89 =cut
90  
91 0 ▶sub versions {
Subroutine versions: not called CC=2 SCAR=17.9
Pod documented
92 0 my($self, $obj_id) = @_;
93 map {
94 0 my $o = $self->get_object($_);
95 0 ▶ if (!$o) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o) { } 0 0 0
96 0 warn "Inconsistency in versions($obj_id) detected";
97 0 ();
98 } else {
99 0 $o;
100 }
101 } $self->version_ids($obj_id);
102 }
103  
104 =item objectify_params($id_or_obj, ...)
105  
106 For each parameter in the list, change the argument to be an object of
107 the database.
108  
109 =cut
110  
111 0 ▶sub objectify_params {
Subroutine objectify_params: not called CC=3 SCAR=24.8
Pod documented
112 0 my $self = shift;
113 0 foreach (@_) {
114 0 ▶ if (!UNIVERSAL::isa($_, "WE::Obj")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($_, "WE::Obj")) 0 0 0
115 0 $_ = $self->get_object($_);
116 }
117 }
118 }
119  
120 =item idify_params($id_or_obj, ...)
121  
122 For each parameter in the list, change the argument to be an object
123 identifier if it was an object, or leave it as it was.
124  
125 =cut
126  
127 0 ▶sub idify_params {
Subroutine idify_params: not called CC=3 SCAR=24.8
Pod documented
128 0 my $self = shift;
129 0 foreach (@_) {
130 0 ▶ if (UNIVERSAL::isa($_,"WE::Obj")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_, "WE::Obj")) 0 0 0
131 0 $_ = $_->Id;
132 }
133 }
134 }
135  
136 =item replace_content_from_file($object_id, $filename)
137  
138 Like replace_content, but get contents from file.
139  
140 =cut
141  
142 0 ▶sub replace_content_from_file {
Subroutine replace_content_from_file: not called CC=2 SCAR=17.9
Pod documented
143 0 my($self, $objid, $filename) = @_;
144 0 $self->idify_params($objid);
145 0 ▶ open(F, $filename) or die "Can't open file $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, $filename or die "Can't open file ${filename}: $!" 0 0 0
146 0 local $/ = undef;
147 0 my $new_content = <F>;
148 0 close F;
149 0 $self->replace_content($objid, $new_content);
150 }
151  
152 =item walk($object_id, $sub_routine, @args)
153  
154 Traverse the object hierarchie, beginning at the object with id
155 C<$object_id>. For each object, C<$sub_routine> is called with the
156 object id and optional C<@args>. Note that the subroutine is B<not>
157 called for the start object itself.
158  
159 If there's no persistent connection to the database (i.e. the database
160 was not accessed with -connect => 1), then using
161 B<connect_if_necessary> is advisable for better performance.
162  
163 Here are some examples for using walk.
164  
165 Get the number of descendent objects from the folder with Id
166 C<$folder_id>. The result is in the C<$obj_count> variable:
167  
168 my $obj_count = 0;
169 $objdb->walk($folder_id, sub {
170 my($id, $ref) = @_;
171 $$ref++;
172 }, \$obj_count);
173 warn "There are $obj_count objects in $folder_id\n";
174  
175 Get all released descendant objects. The released state should be
176 recorded in the Release_State member. The resulting list is a flat
177 array.
178  
179 my @results;
180 $objdb->walk($folder_id, sub {
181 my($id) = @_;
182 my $obj = $objdb->get_object($id);
183 if ($obj->Release_State eq 'released') {
184 push @results, $obj;
185 }
186 });
187 # The released objects are in @results.
188  
189 If you want to break the recursion on a condition, simply use an
190 C<eval>-block and C<die> on the condition. See the source code of
191 C<name_to_objid> method for an example.
192  
193 C<walk> uses postorder traversal, that is, subtrees first, node later.
194  
195 Note that the start object itself is not included in the traversal and
196 the subroutine will not be called for it.
197  
198 The returned value of the last callback called with be returned.
199  
200 =item walk_preorder($object_id, $sub_routine, @args)
201  
202 This is like C<walk>, but uses preorder instead of postorder, that is,
203 node first, children later.
204  
205 Note that the start object itself will be included in the traversal.
206 This is different from the C<walk> method.
207  
208 In preorder walk, the traversal of subtrees can be avoided by setting
209 the global variable C<$WE::DB::Obj::prune> to a true value.
210  
211 =cut
212  
213 0 ▶sub walk {
Subroutine walk: not called CC=3 SCAR=24.8
Pod documented
214 0 my($self, $objid, $sub_routine, @args) = @_;
215 0 my $ret;
216 0 $self->idify_params($objid);
217 0 ▶ if (!UNIVERSAL::isa($sub_routine, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($sub_routine, "CODE")) 0 0 0
218 0 die "Second parameter of walk should be code reference";
219 }
220 0 for my $sub_obj_id ($self->children_ids($objid)) {
221 0 $self->walk($sub_obj_id, $sub_routine, @args);
222 0 $ret = $sub_routine->($sub_obj_id, @args);
223 }
224 0 $ret;
225 }
226  
227 0 ▶sub walk_preorder {
Subroutine walk_preorder: not called CC=4 SCAR=30.0
Pod documented
228 0 my($self, $objid, $sub_routine, @args) = @_;
229 0 my $ret;
230 0 $self->idify_params($objid);
231 0 ▶ if (!UNIVERSAL::isa($sub_routine, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($sub_routine, "CODE")) 0 0 0
232 0 die "Second parameter of walk_preorder should be code reference";
233 }
234  
235 {
236 0 local $WE::DB::Obj::prune;
237 0 $ret = $sub_routine->($objid, @args);
238 0 ▶ return $ret if $WE::DB::Obj::prune;
Branch: 1 branch
BranchTrueFalseTotal
if $WE::DB::Obj::prune 0 0 0
239 }
240  
241 0 for my $sub_obj_id ($self->children_ids($objid)) {
242 0 $ret = $self->walk_preorder($sub_obj_id, $sub_routine, @args);
243 }
244 0 $ret;
245 }
246  
247 # XXX Document, and implement walk_up_prepostorder when needed!
248 0 ▶sub walk_prepostorder {
Subroutine walk_prepostorder: not called CC=6 SCAR=37.4
Pod undocumented
249 0 my($self, $objid, $pre_sub_routine, $post_sub_routine, @args) = @_;
250 0 my $ret;
251 0 $self->idify_params($objid);
252 0 ▶ if (!UNIVERSAL::isa($pre_sub_routine, 'CODE') ||
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($pre_sub_routine, "CODE") and UNIVERSAL::isa($post_sub_routine, "CODE")) 0 0 0
Condition0%0/3
UNIVERSAL::isa($pre_sub_routine, "CODE") and UNIVERSAL::isa($post_sub_routine, "CODE")
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($pre_sub_routine, "CODE") and UNIVERSAL::isa($post_sub_routine, "CODE")
UNIVERSAL::isa($pre_sub_routine, "CODE") UNIVERSAL::isa($post_sub_routine, "CODE")
Truth table0%0/3
A and B
A= UNIVERSAL::isa($pre_sub_routine, "CODE")B= UNIVERSAL::isa($post_sub_routine, "CODE")
ABresult
0X0
100
111
253 !UNIVERSAL::isa($post_sub_routine, 'CODE')) {
254 0 die "Second and third parameters of walk_prepostorder should be code references";
255 }
256  
257 {
258 0 local $WE::DB::Obj::prune;
259 0 $ret = $pre_sub_routine->($objid, @args);
260 0 ▶ return $ret if $WE::DB::Obj::prune;
Branch: 1 branch
BranchTrueFalseTotal
if $WE::DB::Obj::prune 0 0 0
261 }
262  
263 0 for my $sub_obj_id ($self->children_ids($objid)) {
264 0 $ret = $self->walk_prepostorder($sub_obj_id, $pre_sub_routine, $post_sub_routine, @args);
265 }
266  
267 {
268 0 local $WE::DB::Obj::prune;
269 0 $ret = $post_sub_routine->($objid, @args);
270 0 ▶ return $ret if $WE::DB::Obj::prune;
Branch: 1 branch
BranchTrueFalseTotal
if $WE::DB::Obj::prune 0 0 0
271 }
272  
273 0 $ret;
274 }
275  
276 =item walk_up($object_id, $sub_routine, @args)
277  
278 Same as C<walk>, but walk the tree up, that is, traverse all parents
279 from the object to the root.
280  
281  
282 =item walk_up_preorder($object_id, $sub_routine, @args)
283  
284 Same as C<walk_up>, but traverse in pre-order, that is, from the
285 object to the root. Note that the object itself is also included in
286 the traversal.
287  
288 In preorder walk, the further traversal of parents can be avoided by
289 setting the global variable C<$WE::DB::Obj::prune> to a true value.
290  
291 =cut
292  
293 0 ▶sub walk_up {
Subroutine walk_up: not called CC=3 SCAR=24.8
Pod documented
294 0 my($self, $objid, $sub_routine, @args) = @_;
295 0 my $ret;
296 0 $self->idify_params($objid);
297 0 ▶ if (!UNIVERSAL::isa($sub_routine, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($sub_routine, "CODE")) 0 0 0
298 0 die "Second parameter of walk_up should be code reference";
299 }
300 0 for my $p_obj_id ($self->parent_ids($objid)) {
301 0 $self->walk_up($p_obj_id, $sub_routine, @args);
302 0 $ret = $sub_routine->($p_obj_id, @args);
303 }
304 0 $ret;
305 }
306  
307 0 ▶sub walk_up_preorder {
Subroutine walk_up_preorder: not called CC=5 SCAR=34.0
Pod documented
308 0 my($self, $objid, $sub_routine, @args) = @_;
309 0 my $ret;
310 0 $self->idify_params($objid);
311 0 ▶ if (!UNIVERSAL::isa($sub_routine, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($sub_routine, "CODE")) 0 0 0
312 0 die "Second parameter of walk_up_preorder should be code reference";
313 }
314  
315 0 local $WE::DB::Obj::prune;
316 0 $ret = $sub_routine->($objid, @args);
317 0 ▶ return $ret if $WE::DB::Obj::prune;
Branch: 1 branch
BranchTrueFalseTotal
if $WE::DB::Obj::prune 0 0 0
318  
319 0 for my $p_obj_id ($self->parent_ids($objid)) {
320 0 ▶ if (defined $p_obj_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p_obj_id) 0 0 0
321 0 $ret = $self->walk_up_preorder($p_obj_id, $sub_routine, @args);
322 }
323 }
324 0 $ret;
325 }
326  
327 =item whole_tree([$objid])
328  
329 Return the whole (sub)tree of C<$objid>. If C<$objid> is not given,
330 then return the whole tree. The elements of the tree are structured in
331 a nested array. Each element is a hash of the following elements: Id,
332 Title and isFolder.
333  
334 =cut
335  
336 0 ▶sub whole_tree {
Subroutine whole_tree: not called CC=6 SCAR=37.4
Pod documented
337 0 my($self, $objid, $tree) = @_;
338 0 ▶ $objid = $self->root_object->id if !defined $objid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $objid 0 0 0
339 0 ▶ $tree = [] if !$tree;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree 0 0 0
340 0 my $obj = $self->get_object($objid);
341 0 ▶ if (!$obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
342 0 warn "Can't get object $objid!";
343 0 return;
344 }
345 0 push @$tree, {Id=>$obj->Id, Title=>$obj->Title, isFolder=>$obj->is_folder};
346 0 my @children_ids = $self->children_ids($objid);
347 0 ▶ if (@children_ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@children_ids) 0 0 0
348 0 my $child_tree = [];
349 0 foreach my $cid (@children_ids) {
350 0 $self->whole_tree($cid, $child_tree);
351 }
352 0 push @$tree, $child_tree;
353 }
354 0 $tree;
355 }
356  
357 =item _undirty($object)
358  
359 Return the object with all Dirty flags set to 0.
360  
361 =cut
362  
363 0 ▶sub _undirty {
Subroutine _undirty: not called CC=1 SCAR=6.9
364 0 my($self, $obj) = @_;
365 0 $self->objectify_params($obj);
366 0 $obj->Dirty(0);
367 0 $obj->DirtyAttributes(0);
368 0 $obj->DirtyContent(0);
369 0 $self->replace_object($obj);
370 }
371  
372 =item is_locked($object_id)
373  
374 Return true if the object is locked by someone else.
375  
376 =cut
377  
378 0 ▶sub is_locked {
Subroutine is_locked: not called CC=8 SCAR=42.8
Pod documented
379 0 my($self, $obj) = @_;
380 0 $self->objectify_params($obj);
381 0 ▶ return 0 if !defined $obj->LockedBy || $obj->LockedBy eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $obj->LockedBy or $obj->LockedBy eq "" 0 0 0
Condition0%0/3
not defined $obj->LockedBy or $obj->LockedBy eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $obj->LockedBy or $obj->LockedBy eq ""
not defined $obj->LockedBy $obj->LockedBy eq ""
Truth table0%0/3
not(A) or B
A= not defined $obj->LockedByB= $obj->LockedBy eq ""
ABresult
1X1
011
000
382 0 ▶ return 0 if $obj->LockedBy eq $self->Root->CurrentUser;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->LockedBy eq $self->Root->CurrentUser 0 0 0
383 0 ▶ if ($obj->LockType eq 'SessionLock') {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->LockType eq "SessionLock") 0 0 0
384 0 ▶ if ($self->Root->OnlineUserDB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Root->OnlineUserDB) { } 0 0 0
385 0 my $r = $self->Root->OnlineUserDB->check_logged($obj->LockedBy);
386 0 ▶ if (!$r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
387 0 $self->unlock($obj); # XXX -force => 1 ???
388 }
389 0 return $r;
390 } else {
391 0 return 0;
392 }
393 }
394 0 ▶ return 1 if ($obj->LockType eq 'PermanentLock'); # XXX probably check for existing user?
Branch: 1 branch
BranchTrueFalseTotal
if $obj->LockType eq "PermanentLock" 0 0 0
395 0 warn "Unknown lock type @{[ $obj->LockType ]}, assumed locked";
396 0 1;
397 }
398  
399 =item lock($object_id, -type => $lock_type)
400  
401 Lock the object C<$object_id>. Only single objects can be locked (no
402 folder hierarchies). Locking must be handled in the client by using
403 C<is_locked()>. The C<$lock_type> may have the following values:
404  
405 =over 4
406  
407 =item SessionLock
408  
409 This lock should only be valid for this session. If the user closes
410 the session (either by a logout or by closing the browser window),
411 then the lock will be invalidated.
412  
413 =item PermanentLock
414  
415 This lock lasts over session ends.
416  
417 =back
418  
419 Return the object itself.
420  
421 Now, it should be checked programmatically whether the lock can be set
422 or not (by looking at the value is_locked). It is not clear what is
423 the right solution, because there are version control systems where
424 breaking locks is possible (RCS).
425  
426 =cut
427  
428 0 ▶sub lock {
Subroutine lock: not called CC=3 SCAR=24.8
Pod documented
429 0 my($self, $obj_id, %args) = @_;
430 0 ▶ die "Lock -type is missing" if !$args{-type};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-type"} 0 0 0
431 die "Valid Lock types are SessionLock and PermanentLock"
432 0 ▶ unless $args{-type} =~ /^(Session|Permanent)Lock$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-type"} =~ /^(Session|Permanent)Lock$/ 0 0 0
433 0 $self->idify_params($obj_id);
434 0 my $obj = $self->get_object($obj_id);
435 0 $obj->LockedBy($self->Root->CurrentUser);
436 0 $obj->LockType($args{-type});
437 0 $obj->LockTime(epoch2isodate());
438 0 $self->replace_object($obj);
439 }
440  
441 =item unlock($object_id)
442  
443 Unlock the object with id C<$object_id>.
444  
445 Return the object itself.
446  
447 Now, it should be checked programmatically whether the lock can be
448 unset or not (by looking at the value is_locked). It is not clear what
449 is the right solution, because there are version control systems where
450 breaking locks is possible (RCS).
451  
452 =cut
453  
454 0 ▶sub unlock {
Subroutine unlock: not called CC=1 SCAR=6.9
Pod documented
455 0 my($self, $obj_id) = @_;
456 0 $self->idify_params($obj_id);
457 0 my $obj = $self->get_object($obj_id);
458 0 $obj->LockedBy(undef);
459 0 $obj->LockType(undef);
460 0 $obj->LockTime(undef);
461 0 $self->replace_object($obj);
462 }
463  
464 =item pathobjects($object_or_id [, $parent_obj])
465  
466 For the object or id C<$object_or_id>, the object path is returned.
467 This is similar to the C<pathname> method, but returns a list of
468 objects instead of a pathname.
469  
470 If C<$parent_obj> is given as a object, then the returned pathname is
471 only a partial path starting from this parent object.
472  
473 =cut
474  
475 0 ▶sub pathobjects {
Subroutine pathobjects: not called CC=4 SCAR=30.0
Pod documented
476 0 my($self, $obj, $parent_obj) = @_;
477 0 $self->objectify_params($obj);
478 0 ▶ if (defined $parent_obj && $obj->Id eq $parent_obj->Id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_obj and $obj->Id eq $parent_obj->Id) 0 0 0
Condition0%0/3
defined $parent_obj and $obj->Id eq $parent_obj->Id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parent_obj and $obj->Id eq $parent_obj->Id
defined $parent_obj $obj->Id eq $parent_obj->Id
Truth table0%0/3
A and B
A= defined $parent_objB= $obj->Id eq $parent_obj->Id
ABresult
0X0
100
111
479 0 return ();
480 }
481 0 my @parents = $self->parent_ids($obj->Id);
482 0 ▶ if (@parents) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parents) { } 0 0 0
483 0 ($self->pathobjects($parents[0], $parent_obj), $obj);
484 } else {
485 0 ($obj);
486 }
487 }
488  
489 =item pathobjects_with_cache($object_or_id [, $parent_obj], $cache_hash_ref)
490  
491 As C<pathobjects>, but also use a cache for a faster access.
492  
493 =cut
494  
495 0 ▶sub pathobjects_with_cache {
Subroutine pathobjects_with_cache: not called CC=9 SCAR=45.0
Pod documented
496 0 my($self, $obj, $parent_obj, $cache) = @_;
497 0 ▶ if (!ref $obj && exists $cache->{$obj}) { # get by id
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $obj and exists $cache->{$obj}) 0 0 0
Condition0%0/3
not ref $obj and exists $cache->{$obj}
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $obj and exists $cache->{$obj}
not ref $obj exists $cache->{$obj}
Truth table0%0/3
not(A) and B
A= not ref $objB= exists $cache->{$obj}
ABresult
0X0
100
111
498 0 return @{ $cache->{$obj} };
499 }
500 0 $self->objectify_params($obj);
501 0 ▶ return () if !$obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
502 0 my $objid = $obj->Id;
503 0 ▶ if (exists $cache->{$objid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache->{$objid}) 0 0 0
504 0 return @{ $cache->{$objid} };
505 }
506 0 ▶ if (defined $parent_obj && $objid eq $parent_obj->Id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_obj and $objid eq $parent_obj->Id) 0 0 0
Condition0%0/3
defined $parent_obj and $objid eq $parent_obj->Id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parent_obj and $objid eq $parent_obj->Id
defined $parent_obj $objid eq $parent_obj->Id
Truth table0%0/3
A and B
A= defined $parent_objB= $objid eq $parent_obj->Id
ABresult
0X0
100
111
507 0 $cache->{$obj->Id} = [];
508 0 return ();
509 }
510 0 my @parents = $self->parent_ids($objid);
511 0 ▶ if (@parents) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parents) { } 0 0 0
512 0 ▶ if (exists $cache->{$parents[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$cache{$parents[0]}) { } 0 0 0
513 0 (@{ $cache->{$parents[0]} }, $obj);
514 } else {
515 0 my @parent_parents = $self->pathobjects_with_cache($parents[0], $parent_obj);
516 0 $cache->{$parents[0]} = [@parent_parents];
517 0 (@parent_parents, $obj);
518 }
519 } else {
520 0 ($obj);
521 }
522 }
523  
524 =item name_to_objid($name)
525  
526 Return the object id for the object containing the Attribute
527 C<Name=$name>. If there is no such object, undef is returned. Note: This
528 method may or may not be efficient, depending whether there is an
529 index database (C<NameDB>) or not.
530  
531 =cut
532  
533 0 ▶sub name_to_objid {
Subroutine name_to_objid: not called CC=3 SCAR=24.8
Pod documented
534 0 my($self, $name) = @_;
535 0 my $objid;
536 0 ▶ if ($self->Root->NameDB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Root->NameDB) 0 0 0
537 0 $objid = $self->Root->NameDB->get_id($name);
538 0 ▶ return $objid if defined $objid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $objid 0 0 0
539 }
540 # for backward compatibility (database without name.db)
541 0 eval {
542 0 local $SIG{__DIE__};
543 0 ▶ $self->walk($self->root_object->Id, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
544 0 my($id) = @_;
545 0 my $obj = $self->get_object($id);
546 0 ▶ if (defined $obj->Name && $obj->Name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->Name and $obj->Name eq $name) 0 0 0
Condition0%0/3
defined $obj->Name and $obj->Name eq $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $obj->Name and $obj->Name eq $name
defined $obj->Name $obj->Name eq $name
Truth table0%0/3
A and B
A= defined $obj->NameB= $obj->Name eq $name
ABresult
0X0
100
111
547 0 $objid = $obj->Id;
548 0 die "Found";
549 }
550 0 });
551 };
552 0 $objid;
553 }
554  
555 15 1;
556  
557 __END__
« WE/Util/AtJobManager.pm ↑ Summary WE/DB/Content.pm »