Pipeline/Services.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 37 CC 5 SCAR 23.9
CC
5
Cov
0%
param
20.0
response
6.0
load
2.0
CRAP 10.9
1 package WWW::Pipeline::Services;
2 $VERSION = '0.1';
3  
4 #-- pragmas ----------------------------
5 use strict;
6 use warnings;
7  
8 =head1 WWW::Pipeline::Services
9  
10 This package provides basic services for WWW::Pipeline applications,
11 namely a C<param()> method and a C<response()> method.
12  
13 =cut
14  
15 #===============================================================================
16 sub load {
17 my( $class, $pipeline, $params ) = @_;
18  
19 my $self = bless {
20 _params => $params,
21 _response => ''
22 }, $class;
23
24 $pipeline->addServices (
25 param => sub { $self->param(@_) },
26 response => sub { $self->response(@_) }
27 );
28  
29 return $self;
30 }
31  
32 #===============================================================================
33  
34 =head2 Services
35  
36 =head3 param
37  
38 #set
39 $pipeline->param('name',$value);
40 $pipeline->param( name2 => $value2 )
41  
42 #retrieve
43 $pipeline->param('name');
44
45 #delete
46 $pipeline->param('name',undef);
47  
48  
49 the C<param> service provides a storage location for data to be shared between
50 phases for the duration of the pipline.
51  
52 =cut
53  
54 sub param {
55 my( $self, $pipeline, $key, $value ) = @_;
56  
57 if( @_ == 4 ) {
58 return $self->{_params}{$key} = $value
59 if defined $value;
60  
61 return delete $self->{_params}{$key};
62 }
63  
64 return defined $self->{_params}{$key}
65 ? $self->{_params}{$key}
66 : undef;
67 }
68  
69 #-------------------------------------------------------------------------------
70  
71 =head3 response
72  
73 #get
74 $pipeline->response();
75  
76 #set
77 $pipeline->response($value);
78  
79 the C<response> service provides a storage location for text to be sent back
80 to the requester until the application deems appropriate to send it.
81  
82 =cut
83  
84 sub response {
85 my( $self, $pipeline, $value ) = @_;
86  
87 $self->{_response} = $value if @_ == 3;
88  
89 return $self->{_response};
90 }
91  
92 #========
93 1;
94  
95 =head2 Authors
96  
97 Stephen Howard <stephen@thunkit.com>
98  
99 =head2 License
100  
101 This module may be distributed under the same terms as Perl itself.
102  
103 =cut