RWDE/Web/AbstractCommand.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 121 CC 5 SCAR 15.5
CC
5
Cov
0%
baggage_handling
12.0
FIELDNAME
6.0
AUTOLOAD
6.0
CRAP 4.7
1 package RWDE::Web::AbstractCommand;
2  
3 use strict;
4  
5 use RWDE::DB::Record;
6 use RWDE::Exceptions;
7  
8 use vars qw($VERSION);
9 $VERSION = sprintf "%d", q$Revision: 509 $ =~ /(\d+)/;
10  
11 sub new {
12 my ($proto, $params) = @_;
13  
14 my $class = ref($proto) || $proto;
15  
16 my $self = { _data => {}, };
17  
18 bless $self, $class;
19  
20 $self->helper($$params{helper});
21  
22 $self->initialize($params);
23  
24 return $self;
25 }
26  
27 sub initialize {
28 my ($self, $params) = @_;
29  
30 my $helper = $$params{helper};
31  
32 my $req = $helper->get_req();
33  
34 $req->print_header({ pagetype => $helper->get_pagetype()});
35  
36 return ();
37 }
38  
39 =pod
40  
41 =head2 baggage_handling
42  
43 =cut
44  
45 sub baggage_handling {
46 my ($self, $params) = @_;
47  
48 my @search_terms = @{ $$params{search_terms} };
49  
50 my $session = $self->helper->get_session();
51  
52 my $formdata = $self->helper->get_formdata();
53  
54 my $baggage;
55  
56 #reset the baggage hash if we are starting a new search
57 if ($$formdata{init_baggage}) {
58  
59 foreach my $param (@search_terms) {
60 if (defined $$formdata{$param}) {
61 $$baggage{$param} = $$formdata{$param};
62 }
63 }
64 $session->baggage($baggage);
65 }
66  
67 #otherwise we need those variables copied into our formdata
68 else {
69 $baggage = $session->baggage;
70  
71 foreach my $key (keys %{$baggage}) {
72 $$formdata{$key} = $$baggage{$key};
73 }
74 }
75  
76 return ();
77 }
78  
79 sub execute {
80 my ($self, $params) = @_;
81  
82 warn " Abstract Command execute - are you sure you don't want to do anything more specific here? ";
83  
84 return ();
85 }
86  
87 =head2 get_missing_hash
88  
89 Create and populate a hash with input from a comma delim string
90  
91 =cut
92  
93 sub parse_missing {
94 my ($self, $params) = @_;
95  
96 my $missing = RWDE::DB::Record->hashify({ string => $$params{info} });
97  
98 my @missing_array;
99 foreach my $key (keys %{$missing}) {
100 push @missing_array, $$missing{$key};
101 }
102 my $missing_string = join(', ', @missing_array);
103  
104 my $info = "Sorry, some of the required information is missing. Did you remember to fill in your <b>($missing_string)</b>? Please enter the missing information and try again.";
105  
106 $self->helper->set_stash({ info => $info });
107  
108 $self->helper->set_stash({ missing => $missing });
109  
110 return ();
111 }
112  
113 =pod
114  
115 =head2 FIELDNAME($field[,$value])
116  
117 All field names of the record are accessible via the field name. If a
118 second parameter is provided, that value is stored as the data,
119 otherwise the existing value if any is returned. Throws an 'undef'
120 exception on error. It is intended to be called by an F<AUTOLOAD()>
121 method from the subclass.
122  
123 Example:
124  
125 $rec->owner_email('new@add.ress');
126 $rec->user_addr2(undef);
127 print $rec->user_fname();
128  
129 Would be converted by F<AUTOLOAD()> in the subclass to calls like
130  
131 $rec->FIELDNAME('owner_email','new@add.ress');
132  
133 and so forth.
134  
135 =cut
136  
137 sub FIELDNAME {
138 my $self = shift;
139 my $name = shift;
140  
141 my $classref = ref($self)
142 or throw RWDE::DevelException({ info => "No method by name: $name could be located. FIELDNAME tried to find the attribute by $name - but the call was on $self, not an object." });
143  
144 $name =~ s/.*://; # strip fully-qualified portion
145  
146 #if you are trying to set data, have a name and the data...
147 if ((defined($name)) && (defined($_[0]))) {
148  
149 #set the data
150 $self->{_data}->{$name} = $_[0];
151 }
152  
153 return $self->{_data}->{$name};
154 }
155  
156 =pod
157
158 =head2 FIELDNAME()
159
160 All field names of the record are accessible via the field name. If a
161 parameter is provided, that value is stored as the data, otherwise the
162 existing value if any is returned. Throws an 'undef' exception on
163 error.
164
165 Example:
166
167 $rec->password('blahblah');
168 print $rec->password();
169
170 =cut
171  
172 use vars qw($AUTOLOAD);
173  
174 sub AUTOLOAD {
175 my ($self, @args) = @_;
176 if (not ref $self) {
177 my ($package, $filename, $line) = caller();
178 throw RWDE::DataBadException(
179 { info => "AbstractCommand::AUTOLOAD invoked with the fieldname: $AUTOLOAD; probably static access to an undefined field/method from $filename Line: $line " . join(':', @args) . "\n" });
180 }
181 return $self->FIELDNAME($AUTOLOAD, @args);
182 }
183  
184 # do nothing. here just to shut up TT when AUTOLOAD is present
185 sub DESTROY {
186  
187 }
188  
189 1;