blib/lib/Pipeline/Store/ISA.pm

filter: Statementstmt 94.6% 53 / 56 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 60.0% 3 / 5 totaltotal 90.5% 77 / 85 CC 10 SCAR 10.3
CC
10
Cov
91%
get
5.4
set
3.0
init
2.0
CRAP 2.8
« blib/lib/Pipeline.pm ↑ Summary blib/lib/Pipeline/Segment/Async.pm »
1 package Pipeline::Store::ISA;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Pipeline::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw ( Pipeline::Store );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Class::ISA;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = "3.12";
12  
13 1 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod documented
14 1 my $self = shift;
15 1 ▶ if ( $self->SUPER::init( @_ )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->SUPER::init(@_)) 1 0 1
16 1 $self->obj_store( {} );
17 1 $self->isa_store( {} );
18 }
19 }
20  
21 18 ▶sub obj_store {
Subroutine obj_store: called CC=2 SCAR=6.9
Pod undocumented
22 18 my $self = shift;
23 18 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 17 18
24 1 $self->{ store } = shift;
25 1 return $self;
26 }
27 17 return $self->{ store };
28 }
29  
30 14 ▶sub isa_store {
Subroutine isa_store: called CC=2 SCAR=6.9
Pod undocumented
31 14 my $self = shift;
32 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 13 14
33 1 $self->{ isa_store } = shift;
34 1 return $self;
35 }
36 13 return $self->{ isa_store };
37 }
38  
39 3 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
40 3 my $self = shift;
41 3 my $obj = shift;
42 3 my @isa = Class::ISA::super_path( ref($obj) );
43 3 my $store = $self->isa_store;
44 3 foreach my $isa (@isa) {
45 6 ▶ if (!exists $self->isa_store->{ $isa }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->isa_store->{$isa}) 2 4 6
46 2 $store->{ $isa } = {};
47 }
48 6 $store->{ $isa }->{ ref($obj) } = 1;
49 #push @{$store->{ $isa }}, ref($obj);
50 }
51 3 $self->obj_store->{ref($obj)} = $obj;
52 3 $self->emit("setting object " . ref($obj));
53 3 return $self;
54 }
55  
56 8 ▶sub get {
Subroutine get: called CC=5 SCAR=16.8
Pod documented
57 8 my $self = shift;
58 8 my $key = shift;
59  
60 8 $self->emit("$key requested");
61  
62 8 ▶ if (exists( $self->obj_store->{ $key })) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->obj_store->{$key}) { } 6 2 8
elsif (exists $self->isa_store->{$key}) { } 2 0 2
63 6 $self->emit("returning object $key");
64 6 return $self->obj_store->{ $key };
65 } elsif (exists( $self->isa_store->{$key})) {
66 2 my @objs;
67 2 foreach my $thing ( keys %{$self->isa_store->{ $key }} ) {
68 4 push @objs, $self->get( $thing );
69 }
70 2 ▶ return [ @objs ] if (@objs > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @objs > 1 2 0 2
71 0 return $objs[0];
72 } else {
73 0 $self->emit("no object $key");
74 0 return undef;
75 }
76 }
77  
78 2 1;
79  
80  
81 =head1 NAME
82  
83 Pipeline::Store::ISA - inheritance-based store for pipelines
84  
85 =head1 SYNOPSIS
86  
87 use Pipeline::Store::ISA;
88  
89 my $store = Pipeline::Store::ISA->new();
90 $store->set( $object );
91 my $object = $store->get( $class );
92  
93 =head1 DESCRIPTION
94  
95 C<Pipeline::Store::ISA> is a slightly more complex implementation of a
96 Pipeline store than C<Pipeline::Store::Simple>. It stores things as in a
97 hashref indexed by classname, and also their inheritance tree. You can add
98 an object to a store by calling the set method with an object, and you can
99 get an object by calling the get method with the classname or parent classname
100 of the object you wish to retrieve.
101  
102 C<Pipeline::Store::ISA> inherits from the C<Pipeline::Store> class and
103 includes its methods also.
104  
105 =head1 METHODS
106  
107 =over 4
108  
109 =item set( OBJECT )
110  
111 The C<set> method stores an object specified by OBJECT in itself. Replaces
112 existing objects of the same type.
113  
114 =item get( SCALAR )
115  
116 The C<get> method attempts to return an object of the class specified
117 by SCALAR. If an object of that class does not exist in the store it
118 returns undef instead. In the case that you request a super class of
119 multiple objects an array reference will be returned containing all
120 the objects that are blessed into child classes of SCALAR.
121  
122 =back
123  
124 =head1 SEE ALSO
125  
126 C<Pipeline>, C<Pipeline::Store>, C<Pipeline::Store::Simple>
127  
128 =head1 AUTHOR
129  
130 James A. Duncan <jduncan@fotango.com>
131  
132 =head1 COPYRIGHT
133  
134 Copyright 2002 Fotango Ltd. All Rights Reserved.
135  
136 This software is distributed under the same terms as Perl itself.
137  
138 =cut
139  
140  
« blib/lib/Pipeline.pm ↑ Summary blib/lib/Pipeline/Segment/Async.pm »