File Coverage

blib/lib/Pipeline/Store.pm
Criterion Covered Total %
statement 30 33 90.9
branch 5 6 83.3
condition 4 6 66.6
subroutine 10 12 83.3
pod 6 7 85.7
total 55 64 85.9


line stmt bran cond sub pod time code
1             package Pipeline::Store;
2              
3 12     12   19051 use strict;
  12         21  
  12         732  
4 12     12   66 use warnings::register;
  12         18  
  12         1455  
5              
6 12     12   1622 use Pipeline::Base;
  12         20  
  12         344  
7 12     12   70 use base qw( Pipeline::Base );
  12         36  
  12         5326  
8              
9             our $VERSION = "3.12";
10              
11             sub new {
12 34     34 1 78 my $class = shift;
13 34 100       6651 if ( $class->in_transaction() ) {
14 5         15 return $::TRANSACTION_STORE;
15             } else {
16 29         223 my $store = $class->SUPER::new( @_ );
17             }
18             }
19              
20             sub start_transaction {
21 23     23 1 35 my $self = shift;
22 23         29 $::TRANSACTION = 1;
23 23         56 $::TRANSACTION_STORE = $self;
24             }
25              
26             sub in_transaction {
27 78     78 0 169 my $self = shift;
28 78         347 $::TRANSACTION;
29             }
30              
31             sub end_transaction {
32 44     44 1 72 my $self = shift;
33 44 100 100     124 if ($self->in_transaction && $self == $::TRANSACTION_STORE) {
34 19         60 $::TRANSACTION = 0;
35             } else {
36 25         186 $self->emit("cannot clear transaction unless it is called by the same object");
37             }
38             }
39              
40             sub init {
41 29     29 1 66 my $self = shift;
42 29 50 33     164 if ($self->SUPER::init( @_ ) && ref($self) ne 'Pipeline::Store') {
43 29         115 return 1;
44             } else {
45 0         0 return 0;
46             }
47             }
48              
49             sub set {
50 0     0 1 0 throw Pipeline::Error::Abstract;
51             }
52              
53             sub get {
54 0     0 1 0 throw Pipeline::Error::Abstract;
55             }
56              
57             sub DESTROY {
58 21     21   3069 my $self = shift;
59 21         104 $self->end_transaction;
60             }
61              
62             1;
63              
64              
65             =head1 NAME
66              
67             Pipeline::Store - defines the interface for Pipeline store classes
68              
69             =head1 SYNOPSIS
70              
71             use Pipeline::Store; # interface class, does very little
72              
73             =head1 DESCRIPTION
74              
75             C provides a constructor and a generic get/set interface
76             for any class implementing a store to sit on a Pipeline. Pipeline stores
77             are singletons inside the dispatch process. Ie, if you attempt to construct
78             a pipeline store in between the dispatch method being called on a pipeline
79             segment and having the method return a value then you will get the same
80             store as that segments store() method.
81              
82             =head1 METHODS
83              
84             The Pipeline class inherits from the C class and therefore
85             also has any additional methods that its superclass may have.
86              
87             =over 4
88              
89             =item new()
90              
91             The C method constructs a new Pipeline::Store object and calls
92             the C method. If the transaction flat is set then it returns
93             the current store singleton.
94              
95             =item init()
96              
97             The C method is called by new() to do any construction-time initialization
98             of an object.
99              
100             =item start_transaction
101              
102             Sets the transaction flag, which makes the store object that this is called on a
103             singleton until end_transaction is called.
104              
105             =item end_transaction
106              
107             Clears the transaction flag, which lets you construct new pipeline stores.
108              
109             =item store( [ store ] )
110              
111             The C method gets or sets the store in a Pipeline::Store object. Unless C
112             is changed the store is set at construction time to a hash reference.
113              
114             =item get()
115              
116             Does nothing in Pipeline::Store - exists as a placeholder for subclasses.
117              
118             =item set()
119              
120             Does nothing in Pipeline::Store - exists as a placeholder for subclasses.
121              
122             =back
123              
124             =head1 SEE ALSO
125              
126             C, C, C
127              
128             =head1 COPYRIGHT
129              
130             Copyright 2003 Fotango Ltd. All Rights Reserved
131              
132             This module is released under the same license as Perl itself.
133              
134             =head1 AUTHOR
135              
136             James A. Duncan
137              
138             =cut