ASP/FormHandler.pm untested

filter: Statementstmt 0.0% 0 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 16 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1  
2 package Apache2::ASP::FormHandler;
3  
4 use strict;
5 use warnings 'all';
6 use base 'Apache2::ASP::HTTPHandler';
7 use vars __PACKAGE__->VARS;
8  
9 1;# return true:
10  
11 =pod
12  
13 =head1 NAME
14  
15 Apache2::ASP::FormHandler - Base class for form handlers
16  
17 =head1 SYNOPSIS
18  
19 package mysite::contact::form;
20
21 use strict;
22 use warnings 'all';
23 use base 'Apache2::ASP::FormHandler';
24 use vars __PACKAGE__->VARS;
25
26 sub run {
27 my ($s, $context) = @_;
28
29 if( my $errors = $s->validate( $context ) ) {
30 $Session->{validation_errors} = $errors;
31 $Session->{__lastArgs} = $Form;
32 return $Response->Redirect( $ENV{HTTP_REFERER} );
33 }
34
35 # Do stuff:
36
37 # Finally:
38 return $Response->Redirect( "/some/other/place.asp" );
39 }
40
41 sub validate {
42 my ($s, $context) = @_;
43
44 my $errors = { };
45
46 # Did they fill out the form?
47 foreach my $field (qw/ name email message /) {
48 $errors->{$field} = "Required"
49 unless $Form->{$field};
50 }
51
52 return $errors if keys(%$errors);
53 }
54
55 1;# return true:
56  
57 =head1 DESCRIPTION
58  
59 C<Apache2::ASP::FormHandler> is an empty subclass of L<Apache2::ASP::HTTPHandler>
60 and adds nothing of its own.
61  
62 It provides a starting point for all other form handlers.
63  
64 All form handlers should inherit from C<Apache2::ASP::FormHandler> or one of its
65 subclasses.
66  
67 Although the author is a B<Big Fan> of MVC, he does not like to be constantly beat
68 over the head with the MVC two-by-four.
69  
70 The style of MVC available here is very much like that found in ASP.Net's MVC,
71 though somehow it predates the ASP.Net version by more than 2 years.
72
73 =head1 BUGS
74
75 It's possible that some bugs have found their way into this release.
76
77 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
78
79 =head1 HOMEPAGE
80
81 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
82 of Apache2::ASP in action.
83
84 =head1 AUTHOR
85
86 John Drago L<mailto:jdrago_999@yahoo.com>
87
88 =head1 COPYRIGHT AND LICENSE
89
90 Copyright 2007 John Drago, All rights reserved.
91
92 This software is free software. It may be used and distributed under the
93 same terms as Perl itself.
94
95 =cut