File Coverage

blib/lib/Pixie/FinalMethods.pm
Criterion Covered Total %
statement 18 28 64.2
branch 7 10 70.0
condition n/a
subroutine 4 7 57.1
pod n/a
total 29 45 64.4


line stmt bran cond sub pod time code
1             package Pixie::FinalMethods;
2              
3             =head1 NAME
4              
5             Pixie::FinalMethods - 'fixed' methods that Pixie uses
6              
7             =head1 SYNOPSIS
8              
9             use Pixie::FinalMethods;
10              
11             $hash{$some_object->PIXIE::address} = ...;
12              
13             =head1 DESCRIPTION
14              
15             Pixie has some helper methods that it makes sense to use in an object
16             oriented fashion any object. But these same methods should I be
17             overridden. One option is just to define these methods in UNIVERSAL
18             and to rely on people to be polite. But we are a little more
19             defensive. We push our final methods into the PIXIE namespace. Perl
20             allows you to make a method call to a fully specified method name, so
21             we do that. And it works.
22              
23             This means that any methods we shove into UNIVERSAL are there to be
24             overridden L, though some are more overrideable
25             than others.
26              
27             =cut
28              
29             $Pixie::FinalMethods::Loaded++;
30              
31             package PIXIE;
32              
33 16     16   7999 use Pixie::Info;
  16         43  
  16         7935  
34              
35              
36             sub address {
37 0     0   0 my $self = shift;
38 0         0 my $orig_class = ref($self);
39              
40 0         0 bless $self, 'Class::Whitehole';
41 0         0 my $addr = 0 + $self;
42 0         0 bless $self, $orig_class;
43 0         0 return $addr;
44             }
45              
46             sub set_oid {
47 0     0   0 my $self = shift;
48 0         0 $self->PIXIE::get_info->set__oid(shift);
49 0         0 return $self;
50             }
51              
52             sub oid {
53 33     33   56 my $self = shift;
54 33         136 $self->PIXIE::get_info->_oid;
55             }
56              
57             sub managing_pixie {
58 0     0   0 get_info($_[0])->pixie;
59             }
60              
61              
62             sub get_info {
63 69     69   12516 my $self = shift;
64 69 50       524 die "Can't get info about a ", ref($self) if $self->isa('Pixie::ObjectInfo');
65 69         93 my $info;
66 69 100       326 unless ( $info = Pixie::Info::px_get_info($self)) {
67 28         176 $info = Pixie::ObjectInfo->make_from($self);
68 28         135 $self->PIXIE::set_info($info);
69             }
70 69         243 return $info;
71             }
72              
73             sub set_info {
74 33     33   56 my $self = shift;
75 33         67 my $info = shift;
76              
77 33 50       251 die "Can't set info about a ", ref($self) if $self->isa('Pixie::ObjectInfo');
78 33 100       245 die "Info must be a Pixie::ObjectInfo" unless defined($info) ? $info->isa('Pixie::ObjectInfo') : 1;
    50          
79 33         121 Pixie::Info::px_set_info($self, $info);
80 33         86 return $self;
81             }
82              
83              
84             1;