lib/HTTP/Monkeywrench.pm

filter: Statementstmt 84.6% 149 / 176 Branchbran 57.3% 39 / 68 Conditioncond 21.4% 6 / 28 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 94.1% 16 / 17 Podpod 62.5% 5 / 8 totaltotal 69.2% 216 / 312 CC 52 SCAR 33.0
CC
52
Cov
71%
test
45.5
send_monkeymail
30.0
get_response
15.8
CRAP 27.0
↑ Summary
1 # HTTP::Monkeywrench.pm
2 # ---------------------------------------------------------
3 # $Revision: 1.13 $
4 # $Date: 2000/09/12 00:14:54 $
5 # ---------------------------------------------------------
6  
7 =head1 NAME
8  
9 HTTP::Monkeywrench - Web testing application
10  
11 =head1 SYNOPSIS
12  
13 use HTTP::Monkeywrench;
14 $session = [
15 {
16 name =E<gt> 'URL Name',
17 url =E<gt> 'http://url',
18 }
19 ];
20 HTTP::Monkeywrench-E<gt>test($session);
21  
22 =head1 REQUIRES
23  
24 CGI
25 Net::SMTP
26 HTTP::Cookies
27 LWP::UserAgent
28 Time::HiRes
29 Data::Dumper
30  
31 =cut
32  
33 =head1 EXPORTS
34  
35 None
36  
37 =head1 DESCRIPTION
38  
39 HTTP::Monkeywrench is a test-harness application to test the integrity
40 of a user's path through a web site.
41  
42 To run HTTP::Monkeywrench-E<gt>test(), first set up a Perl script that contains
43 sessions (described below), settings if desired (also described below),
44 and a call to HTTP::Monkeywrench-E<gt>test(), passing it the settings hashref first,
45 followed by the desired session hashrefs you want to test.
46 HTTP::Monkeywrench-E<gt>test($settings, $session1,... $sessionN)
47  
48 HTTP::Monkeywrench can also be used in an object-oriented fashion -- simply
49 take the result of HTTP::Monkeywrench-E<gt>new (optionally passing the settings
50 hashref) and call the test() method against it as above (optionally omitting
51 the settings hashref.)
52  
53 Each session arrayref contains one or more hashrefs, called clicks,
54 which contain descriptive elements of a specific web page to be tested.
55 The elements are described below under SESSION.
56  
57 =head1 SESSION
58  
59 =over 4
60  
61 =item C<$session1> (ARRAYREF of HASHREFS)
62  
63 A session is an arrayref of complex hashrefs that can be sent to the
64 C<HTTP::Monkeywrench-E<gt>test> application to perform tests on a website
65 as a virtual user.
66  
67 The following keys can be in each 'Click' hashref.
68 Fields with a "*" are required:
69  
70 =back
71  
72 =over 8
73  
74 =item name (SCALAR)
75  
76 A name to visually reference that 'click' in the reports
77  
78 =item *url (SCALAR)
79  
80 The url for Monkeywrench to test for that click.
81  
82 =item params (HASHREF)
83  
84 The params to send to dynamic pages and cgi's.
85 Params should be set up as such: { username => 'joe', password => 'blow' }
86  
87 =item method (SCALAR)
88  
89 'method' should be either 'POST' or 'GET'. If method is left
90 blank, method will default to 'GET'.
91  
92 =item auth (ARRAYREF)
93  
94 'auth' is the username and password if the site your are testing
95 is password protected. 'auth' params must be passed to each
96 element of a session that is accessing the same site.
97 Example: ['username','password']
98  
99 =item success_res (ARRAYREF)
100  
101 An arrayref of items for Monkeywrench to test for their existence.
102 Each element of the array can either be a text string or a regexp object.
103 If a string from success_res is not found in the page, Monkeywrench
104 will report an error.
105 EXAMPLE: ['string',qr/regexp_object/,'etc']
106  
107 =item error_res (ARRAYREF)
108  
109 The same as success_res, except that an error will only be reported
110 if strings in error_res ARE found on the page being tested.
111  
112 =item cookies (ARRAYREF of ARRAYREFS)
113  
114 A preset cookie can be sent to a page. In order to send a cookie to
115 a page the following elements should be included as an arrayref:
116  
117 [$version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest]
118  
119 An example cookie would look like:
120  
121 [['0', 'sessnum', 'expires&2592000&type&consumer', '/','cookiemonster.org', '8014', '', '', '2000-09-11 16:15:15Z', '']],
122  
123 =item acceptcookie (BIT)
124  
125 A numeric flag set to 1 or 0 to tell Monkeywrench if it should accept and
126 save a cookie passed from a server.
127 Default is 0, cookies will not be accepted.
128  
129 =item sendcookie (BIT)
130  
131 A numeric flag set to 1 or 0 to tell Monkeywrench to send a saved or
132 pre made cookie back to the server. Default is 0, cookies will not be sent.
133  
134 =item showhtml (BIT)
135  
136 A numeric flag set to 1 or 0 to have the source html of a page displayed
137 within the report. When set to 1 the reports can get messy if the page
138 is heavy on html.
139  
140 =back
141  
142 =head1 SETTINGS HASH
143  
144 =over 4
145  
146 =item $settings (HASHREF)
147  
148 The settings hash is optional as are each of the elements of $settings.
149 Elements that are not declared or set are defaulted to 0 (off).
150  
151 =back
152  
153 =over 8
154  
155 =item match_detail (BIT)
156  
157 A numeric flag set to 1 or 0. If set to 1 Match detail shows all of
158 the reports of success_res and error_res no matter if they pass or fail.
159  
160 =item show_cookies (BIT)
161  
162 A numeric flag set to 1 or 0. If set to 1 show_cookies will show all
163 the cookies in the report, either passed from the session or sent
164 from the server.
165  
166 =item smtp_server (SCALAR)
167  
168 The SMTP server to be used by Net::SMTP. Only required if user wants
169 output of Monkeywrench to be sent to an email address.
170  
171 =item send_mail (ARRAYREF)
172  
173 The send_mail arrayref is also only required if user plans on sending
174 output to one or more email addresses.
175  
176 =item send_if_err (BIT)
177  
178 The send_if_err bit is a flag that should be set to either 1 or 0 and
179 is only used if the user wants the Monkeywrench output sent via email.
180 If set to 1 the output will only be sent to the email address(es) in
181 the event of a failure in the success or error checking or any result
182 code other than 200.
183  
184 =item print_results (BIT)
185  
186 If set to 1, the results will be printed to the screen. If set to 0 nothing
187 will be printed to the screen. The default setting is 1.
188  
189  
190 =back
191  
192 =cut
193  
194 =head1 METHODS
195  
196 =over 4
197  
198 =cut
199  
200 package HTTP::Monkeywrench;
201  
202 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
203 1 ▶use vars qw($totaltime $totalerrs @sessiontime $debug $default_settings $content);
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 1 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
206 1 ▶use Net::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
207 1 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
208 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 #use LWP::Debug qw(+); # spits out a lot of helpful LWP debugging
210  
211 1 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
212 1 ▶use Data::Dumper; # also used for debugging purposes
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
215 1 $HTTP::Monkeywrench::REVISION = (qw$Revision: 1.13 $)[-1];
216 1 $HTTP::Monkeywrench::VERSION = '1.0';
217  
218 1 $CGI::NO_DEBUG = 1; # again, debugging
219 1 $debug = undef; # set to 1 if you want to see debugging output
220 1 $default_settings = {
221 match_detail => 1,
222 show_cookies => 1,
223 smtp_server => undef,
224 send_mail => undef,
225 send_if_err => 0,
226 print_results => 1
227 };
228 }
229  
230 1 $totalerrs = 0; # initialize the total errors string
231  
232 =item C<new> ( [ \%settings ] )
233  
234 Returns a new Monkeywrench object. Optionally takes a settings hash.
235  
236 =cut
237 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
238 1 my $proto = shift;
239 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
240 1 my $self = bless({}, $class);
241 1 $self->settings(shift);
242 1 $self->{'ua'} = new LWP::UserAgent;
243 1 $self->{'ua'}->agent('Monkeywrench/'.$HTTP::Monkeywrench::VERSION . $self->{'ua'}->agent);
244 1 $self->{'cookie_jar'} = HTTP::Cookies->new;
245 1 $self->{'cgi'} = CGI->new('');
246 1 return $self;
247 } # END method new
248  
249 =item C<settings> ( $self, [ \%settings ] )
250  
251 Returns settings hash. Passing hashref will change settings in object.
252  
253 =cut
254 7 ▶sub settings {
Subroutine settings: called CC=6 SCAR=18.8
Pod documented
255 7 my $self = shift;
256 7 ▶ return undef unless (ref $self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 7 7
257 7 ▶ if (my $settings = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $settings = shift()) 1 6 7
258 1 ▶ warn "SETTINGS ==> " . Dumper($settings) if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $HTTP::Monkeywrench::debug 0 1 1
259 1 ▶ unless (ref($settings) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $settings eq "HASH") 0 1 1
260 0 carp('Settings must be called with hashref...\n');
261 0 return undef;
262 }
263  
264 $self->{'settings'} = {
265 1 ▶ map { $_ => defined($settings->{$_}) ? $settings->{$_} : $default_settings->{$_} }
Branch: 1 branch
BranchTrueFalseTotal
defined $settings->{$_} ? : 3 3 6
266 keys %$default_settings };
267 }
268
269 7 return $self->{'settings'};
270 } # END method settings
271
272 3 ▶sub ua { $_[0]->{'ua'}; }
Subroutine ua: called CC=1 SCAR=0.0
Pod undocumented
273 2 ▶sub cookie_jar { $_[0]->{'cookie_jar'}; }
Subroutine cookie_jar: called CC=1 SCAR=0.0
Pod undocumented
274 1 ▶sub cgi { $_[0]->{'cgi'}; }
Subroutine cgi: called CC=1 SCAR=0.0
Pod undocumented
275  
276 =item C<test> ( [ \%settings ], \@session [ , \@session, ... ] )
277  
278 Usable as both a static method and object method.
279 Runs a series Monkeywrench tests on a web server using the parameters set forth in the
280 sessions you pass.
281  
282 =cut
283 1 ▶sub test {
Subroutine test: called CC=32 SCAR=38.2
Pod documented
284 1 my $self = shift;
285 1 ▶ unless (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 1 0 1
286 1 ▶ $self = $self->new(ref($_[0]) eq 'HASH' ? shift : ());
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 0 1
287 }
288 #my $settings = $self->settings((ref($_[0]) eq 'HASH') && shift);
289 1 my @sessions = @_;
290 1 my $q = $self->cgi();
291 1 my $sessnum = 0;
292 1 my $return = {};
293 1 my $res;
294  
295 1 $content .= sprintf("============================== Monkeywrench %.2f ==============================\n",($HTTP::Monkeywrench::REVISION));
296  
297 1 foreach my $session (@sessions) {
298 2 $content .= "Session $sessnum\n";
299 2 my $clicknum = 0;
300 2 foreach (@$session) {
301 3 my $click = { %$_ }; # Make a copy so we don't stomp on the original
302 3 $click->{'params'} = join('&', map{ $q->escape($_) . '=' . $q->escape($click->{'params'}{$_} ) } keys %{$click->{'params'}} );
303 3 ▶ $click->{'method'} = $click->{'method'} ? $click->{'method'} : 'GET';
Branch: 1 branch
BranchTrueFalseTotal
$click->{'method'} ? : 2 1 3
304 3 ▶ $click->{'showhtml'} = $click->{'showhtml'} || 0;
Condition50%1/2
$click->{'showhtml'} || 0
l!l
03
MC/DC0%0/1
$click->{'showhtml'} || 0
$click->{'showhtml'}
Truth table50%1/2
A
A= $click->{'showhtml'}
Aresult
11
00
305 3 push(@{ $click->{'urls'} },$click->{'url'});
306
307 3 ▶ if ($click->{'cookies'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($click->{"cookies"}) 3 0 3
308 3 foreach my $cookie (@{ $click->{'cookies'} }) {
309 1 $self->cookie_jar->set_cookie(@$cookie);
310 }
311 }
312  
313 3 my $t1 = [ gettimeofday ];
314 3 $res = $self->get_response($click);
315 3 $return->{ session }[ $sessnum ][ $clicknum ]{ res } = $res->code;
316 3 my $t2 = [ gettimeofday ];
317
318 3 $content .= " Summary for: " . $click->{'name'} . "\n";
319 3 my $r = 1;
320 3 foreach my $url (@{ $click->{'urls'} }) {
321 3 ▶ $content .= scalar (($r==1) ? ' URL: ' : ' Redirect: ') . "$url\n";
Branch: 1 branch
BranchTrueFalseTotal
$r == 1 ? : 3 0 3
322 3 $r++;
323 }
324 3 ▶ if (($click->{'sendcookie'}) && ($self->settings->{'show_cookies'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($click->{"sendcookie"} and $self->settings->{"show_cookies"}) 0 3 3
Condition66%2/3
$click->{"sendcookie"} and $self->settings->{"show_cookies"}
!ll&&!rl&&r
210
MC/DC0%0/2
$click->{"sendcookie"} and $self->settings->{"show_cookies"}
$click->{"sendcookie"} $self->settings->{"show_cookies"}
Truth table66%2/3
A and B
A= $click->{"sendcookie"}B= $self->settings->{"show_cookies"}
ABresult
0X0
100
111
325 0 my $cookie_to_print = $self->cookie_jar->as_string;
326 0 $~ = "COOKIES";
327 0 write;
328 format COOKIES =
329 Cookie:
330 ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
331 $cookie_to_print
332 .
333 }
334 3 my $failed = 0;
335 3 my $success = 0;
336  
337 3 $content .= ' Code: ' . $res->code . ' ' . $res->message . "\n";
338 3 ▶ if ($res->is_redirect || $res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_redirect or $res->is_success) { } 2 1 3
Condition66%2/3
$res->is_redirect or $res->is_success
l!l&&r!l&&!r
021
MC/DC50%1/2
$res->is_redirect or $res->is_success
$res->is_redirect $res->is_success
Truth table66%2/3
A or B
A= $res->is_redirectB= $res->is_success
ABresult
1X1
011
000
339 2 ▶ $content .= " Match Res:\n" if ($click->{'success_res'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"success_res"} 2 0 2
340 2 foreach my $sr (@{ $click->{'success_res'} }) {
341 3 my $result;
342 3 ▶ if ($res->content =~ $sr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->content =~ /$sr/i) { } 2 1 3
343 2 ▶ $result = "PASS" if ($self->settings->{'match_detail'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->settings->{"match_detail"} 2 0 2
344 } else {
345 1 $result = "FAIL";
346 1 $failed++;
347 1 $totalerrs++;
348 }
349 3 pipe (RFH,WFH);
350 format WFH =
351 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>
352 $sr, $result
353 .
354 3 ▶ write WFH if ($result);
Branch: 1 branch
BranchTrueFalseTotal
if $result 3 0 3
355 3 close WFH;
356 3 local $/ = undef;
357 3 $content .= <RFH>;
358 }
359
360 2 ▶ $content .= " Match Error:\n" if ($click->{'error_res'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"error_res"} 2 0 2
361 2 foreach my $er (@{ $click->{'error_res'} }) {
362 2 my $result;
363 2 ▶ if ($res->content =~ $er) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->content =~ /$er/i) { } 1 1 2
364 1 $result = "FAIL";
365 1 $failed++;
366 1 $totalerrs++;
367 } else {
368 1 ▶ $result = "PASS" if ($self->settings->{'match_detail'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->settings->{"match_detail"} 1 0 1
369 }
370 2 pipe (ERR_RFH,ERR_WFH);
371 format ERR_WFH =
372 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>
373 $er, $result
374 .
375 2 ▶ write ERR_WFH if ($result);
Branch: 1 branch
BranchTrueFalseTotal
if $result 2 0 2
376 2 close ERR_WFH;
377 2 local $/ = undef;
378 2 $content .= <ERR_RFH>;
379 }
380
381 } else {
382 1 $content .= " *** Request Failed ***\n"; #. $res->error_as_HTML;
383 }
384  
385 3 $return->{ session }[ $sessnum ][ $clicknum ]{ clicktime } = my $clicktime = tv_interval($t1,$t2);
386 3 $totaltime += $clicktime;
387 3 $return->{ session }[ $sessnum ][ $clicknum ]{ sessiontime } = $sessiontime[$sessnum] += $clicktime;
388 3 $content .= "\n Pageclick: $clicktime second\n"; # must kill clicktime nazis
389 3 $content .= "-------------------------------------------------------------------------------\n";
390 3 $clicknum++;
391 }
392
393 2 $content .= " Session $sessnum: $sessiontime[$sessnum]\n";
394 2 $content .= "===============================================================================\n";
395 2 $sessnum++;
396 }
397
398 1 $content .= "Total Errors: $totalerrs\n";
399 1 $content .= " Total Test: $totaltime seconds\n\n";
400 1 $return->{ totaltime } = $totaltime;
401
402 1 ▶ if ($self->settings->{'send_mail'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->settings->{"send_mail"}) 0 1 1
403 0 ▶ if (($self->settings->{'send_if_err'} == 0) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->settings->{"send_if_err"} == 0 or $self->settings->{"send_if_err"} == 1 and $res->code != 200 || $HTTP::Monkeywrench::totalerrs > 0) 0 0 0
Condition0%0/9
$self->settings->{"send_if_err"} == 0 or $self->settings->{"send_if_err"} == 1 and $res->code != 200 || $HTTP::Monkeywrench::totalerrs > 0
l!l&&r!l&&!r
000
$self->settings->{"send_if_err"} == 1 and $res->code != 200 || $HTTP::Monkeywrench::totalerrs > 0
!ll&&!rl&&r
000
$res->code != 200 or $HTTP::Monkeywrench::totalerrs > 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->settings->{"send_if_err"} == 0 or $self->settings->{"send_if_err"} == 1 and $res->code != 200 || $HTTP::Monkeywrench::totalerrs > 0
$self->settings->{"send_if_err"} == 0 $self->settings->{"send_if_err"} == 1 $res->code != 200 $HTTP::Monkeywrench::totalerrs > 0
Truth table0%0/5
A or B and C or D
A= $self->settings->{"send_if_err"} == 0B= $self->settings->{"send_if_err"} == 1C= $res->code != 200D= $HTTP::Monkeywrench::totalerrs > 0
ABCDresult
1XXX1
011X1
01011
00XX0
01000
404 (($self->settings->{'send_if_err'} == 1) && ((($res->code != 200) || ($totalerrs > 0))))) {
405 0 ▶ $self->send_monkeymail($content,$self->settings->{'smtp_server'},$self->settings->{'send_mail'})
Branch: 1 branch
BranchTrueFalseTotal
$self->send_monkeymail($HTTP::Monkeywrench::content, $self->settings->{"smtp_server"}, $self->settings->{"send_mail"}) or warn "Unable to send monkeymail" 0 0 0
406 || warn "Unable to send monkeymail";
407 }
408 }
409 1 ▶ print $content if $self->settings->{'print_results'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->settings->{"print_results"} 0 1 1
410 1 return $return;
411 } # end method test
412  
413  
414 =item C<get_response> ($click)
415  
416 get_response is a recursive method that loops through all
417 possible redirects until a final response is returned,
418 which is then returned to the caller.
419  
420 =cut
421 3 ▶sub get_response {
Subroutine get_response: called CC=11 SCAR=27.6
Pod documented
422 3 my $self = shift;
423 3 my $click = shift;
424 3 ▶ my $method = ($click->{'REDIRECT'} ? 'GET' : $click->{'method'});
Branch: 1 branch
BranchTrueFalseTotal
$click->{'REDIRECT'} ? : 0 3 3
425 3 ▶ my $req = HTTP::Request->new($method => $click->{'urls'}->[-1] . (($method eq 'GET') ? '?'.$click->{'params'} : ''));
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 3 0 3
426
427 3 ▶ $req->authorization_basic($click->{'auth'}->[0], $click->{'auth'}->[1]) if ($click->{'auth'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"auth"} 3 0 3
428 3 ▶ $req->content($click->{'params'}) unless ($click->{'REDIRECT'});
Branch: 1 branch
BranchTrueFalseTotal
unless $click->{"REDIRECT"} 3 0 3
429 3 ▶ $self->cookie_jar->add_cookie_header($req) if ($click->{'sendcookie'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"sendcookie"} 1 2 3
430
431 3 ▶ $content .= "\$req ==> " . Dumper($req) if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $HTTP::Monkeywrench::debug 0 3 3
432  
433 3 my $res = $self->ua->request($req);
434
435 3 ▶ $content .= "\$res ==> " . Dumper($res) if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $HTTP::Monkeywrench::debug 0 3 3
436 3 ▶ $content .= "RESPONSE ==> " . $res->content . "\n" if ($click->{'showhtml'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"showhtml"} 0 3 3
437  
438 3 ▶ $self->cookie_jar->extract_cookies($res) if ($click->{'acceptcookie'});
Branch: 1 branch
BranchTrueFalseTotal
if $click->{"acceptcookie"} 0 3 3
439  
440 3 ▶ if ($res->is_redirect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_redirect) { } 0 3 3
441 0 $click->{'REDIRECT'} = 1;
442 0 push(@{ $click->{'urls'} },$res->header('Location'));
443 0 return $self->get_response($click)
444 } else {
445 3 return $res;
446 }
447 } # end method get_response
448  
449  
450 =item C<send_monkeymail> ( $content, \$smtp_server \@address )
451  
452 send_monkeymail is called if the config script has an
453 email address and depending on how send_if_err is setup.
454 $content is the output of the session(s) called by the
455 config script and the \@address arrayref contains the
456 address(es) that the output will be sent to. $smtp_server
457 is the smtp server for Net::SMTP to connect to and is also
458 required in order for send_monkeymail to be called.
459  
460 =cut
461 0 ▶sub send_monkeymail {
Subroutine send_monkeymail: not called CC=5 SCAR=34.0
Pod documented
462 0 my $self = shift;
463 0 ▶ my $content = shift || 'ERROR: NO OUTPUT';
Condition0%0/2
shift() || 'ERROR: NO OUTPUT'
l!l
00
MC/DC0%0/1
shift() || 'ERROR: NO OUTPUT'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
464 0 ▶ my $smtp_server = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
465 0 ▶ my $address = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
466
467 0 ▶ my $smtp = Net::SMTP->new($smtp_server) || return undef;
Condition0%0/2
'Net::SMTP'->new($smtp_server) || (return undef)
l!l
00
MC/DC0%0/1
'Net::SMTP'->new($smtp_server) || (return undef)
'Net::SMTP'->new($smtp_server)
Truth table0%0/2
A
A= 'Net::SMTP'->new($smtp_server)
Aresult
11
00
468 0 $smtp->mail($ENV{'USER'});
469 0 $smtp->to(@{$address});
470  
471 0 $smtp->data();
472 0 $smtp->datasend("From: " . $ENV{'USER'} . "\n");
473 0 $smtp->datasend("To: @{$address}\n");
474 0 $smtp->datasend("Subject: Monkeywrench Output\n");
475 0 $smtp->datasend( "\n" . $content );
476 0 $smtp->dataend();
477
478 0 $smtp->quit;
479 }
480  
481  
482 1 1;
483  
484 __END__
↑ Summary