Apache2-ASP
view release on metacpan or search on metacpan
lib/Apache2/ASP/Manual/BestPractices.pod view on Meta::CPAN
else
{
$errors->{username} = $props->username->is_missing;
}# end if()
# password:
if( length($Form->{password}) )
{
# Password cannot contain whitespace:
if( $Form->{password} =~ m/\s/ )
{
$errors->{password} = $props->password->is_invalid;
}# end if()
}
else
{
$errors->{password} = $props->password->is_missing;
}# end if()
# Only check to see if the user exists if we haven't encountered other errors:
unless( keys(%$errors) )
{
if( ! find_user( ... ) )
{
$errors->{general} = $props->general->fail;
}# end if()
}# end unless()
return unless keys(%$errors);
return $errors;
}# end validate()
1;# return true:
=head1 UNIT TESTING
Unit testing was the number one reason behind the development of Apache2::ASP.
Apache2::ASP offers a unit testing environment that is not dependent on Apache
or any other server.
Unit tests are made possible via instances of L<Apache2::ASP::Test::Base> and
use L<Apache2::ASP::Test::UserAgent> to make "requests" to ASP scripts and handlers
in your Apache2::ASP web application.
=head2 Example
Supposing your website is at C</var/www/www.example.com>, create a folder C</t>
at C</var/www/www.example.com/t>.
Inside C</t> create C</t/00-basic.t> which contains:
#!/usr/bin/env perl -w
use strict;
use warnings 'all';
use Test::More 'no_plan';
use base 'Apache2::ASP::Test::Base';
# Create our base test object:
my $s = __PACKAGE__->SUPER::new();
# Make a request:
my $res = $s->ua->get("/index.asp");
# $res is a normal HTTP::Response object:
ok( $res->is_success => "Got /index.asp" );
like $res->content, qr/Hello, World/, "Contents look right";
is( $res->header('content-type') => 'text/html' );
Run your tests with:
prove t
All of your tests will be run.
=head1 CODE COVERAGE
Along with unit testing, code coverage is another great reason to use Apache2::ASP.
Just by using the L<Devel::Cover> utility C<cover> you can get code coverage
for not only your website's libraries, but also its handlers and ASP scripts.
=head1 PROFILING
Profiling an Apache2::ASP web application fits right in with your unit tests and
code coverage.
L<Devel::NYTProf> is an excellent profiler tool for Perl and works very well with
Apache2::ASP web applications.
=head1 ERROR HANDLING
Errors are handled by subclasses of L<Apache2::ASP::ErrorHandler>.
The default ErrorHandler prints a stacktrace to the browser and sends a copy
to the email address specified in your config file.
=head2 Configuration
Open your C</conf/apache2-asp-config.xml> file and look for the following:
<errors>
<error_handler>...</error_handler>
<mail_errors_to>...</mail_errors_to>
<mail_errors_from>...</mail_errors_from>
<smtp_server>...</smtp_server>
</errors>
Make changes as necessary.
=head1 FILE UPLOADS
Almost any time you need to process a file upload, your best bet is to subclass
L<Apache2::ASP::MediaManager>.
See L<Apache2::ASP::MediaManager> for details.
If you really need to do something special, either subclass L<Apache2::ASP::UploadHandler>
or write your own C<mod_perl> handler and submit to it.
( run in 1.013 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )