File Coverage

blib/lib/Pixie/Name.pm
Criterion Covered Total %
statement 38 39 97.4
branch 10 12 83.3
condition 1 2 50.0
subroutine 10 10 100.0
pod 0 8 0.0
total 59 71 83.1


line stmt bran cond sub pod time code
1             package Pixie::Name;
2              
3 25     25   23306 use strict;
  25         45  
  25         14449  
4              
5             our $VERSION = '2.08_02';
6              
7             # TODO: Pixie::Object has a constructor - use it?
8             sub new {
9 4     4 0 843 my $class = shift;
10 4         18 return bless {}, $class;
11             }
12              
13             #-----------------------------------------------------------------------------
14             # Class methods
15             #-----------------------------------------------------------------------------
16              
17             sub oid_for_name {
18 9     9 0 381 my $class = $_[0];
19 9         78 return "";
20             }
21              
22             # TODO: move these class methods into Pixie ? They seem out of place here.
23              
24             # TODO: rename 'name_objects'
25             sub name_object_in {
26 2     2 0 46 my $class = shift;
27 2         4 my($name,$obj,$pixie) = @_;
28 2         8 $pixie->insert
29             ( $class->new->_oid($class->oid_for_name($name))->px_target($obj) );
30             }
31              
32             # TODO: rename 'fetch_named_objects'
33             sub get_object_from {
34 2     2 0 541 my $class = shift;
35 2         4 my($name, $pixie, $strategy) = @_;
36 2 50       11 $class->do_restoration
37             ( defined($strategy)
38             ? $pixie->get_with_strategy( $class->oid_for_name($name), $strategy )
39             : $pixie->get($class->oid_for_name($name))
40             );
41             }
42              
43             # TODO: rename 'restore_targets'
44             sub do_restoration {
45 4     4 0 1766 my $class = shift;
46 4   50     19 my $name_obj = shift || return;
47 4         14 my $target = $name_obj->px_target;
48              
49 4 100       13 if (wantarray) {
50 2 100       6 return map { eval { $_->px_restore } || $_ } @$target;
  4         110  
  4         23  
51             }
52              
53 2 50       11 if ($target->[-1]->isa('Pixie::Proxy')) {
54 0         0 return $target->[-1]->px_restore;
55             }
56              
57 2         76 return $target->[-1];
58             }
59              
60             # TODO: rename 'fetch_named_objects_with_strategy'
61             sub get_object_from_with_strategy {
62 2     2 0 5972 my $class = shift;
63 2         8 my($name, $pixie, $strategy) = @_;
64 2         9 $class->do_restoration
65             ($pixie->get_with_strategy($class->oid_for_name($name), $strategy));
66             }
67              
68             # TODO: rename 'remove_name_from_objects'
69             sub remove_name_from {
70 1     1 0 1344 my $class = shift;
71 1         4 my($name, $pixie) = @_;
72 1         5 $pixie->delete($class->oid_for_name($name));
73             }
74              
75              
76             #-----------------------------------------------------------------------------
77             # Accessors
78             #-----------------------------------------------------------------------------
79              
80             sub _oid {
81 7     7   339 my $self = shift;
82 7 100       17 if (@_) {
83 4         18 $self->{_oid} = shift;
84 4         18 return $self;
85             } else {
86 3         15 return $self->{_oid};
87             }
88             }
89              
90             sub px_target {
91 10     10 0 15 my $self = shift;
92 10 100       26 if (@_) {
93 4         6 $self->{target} = shift;
94 4         21 return $self;
95             } else {
96 6         21 return $self->{target};
97             }
98             }
99              
100             1;