CGI-Application-Plugin-ErrorPage
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/ErrorPage.pm view on Meta::CPAN
goto &Exporter::import;
}
sub add_page_not_found_rm {
my $c = shift;
my %rms = $c->run_modes;
unless( exists $rms{'AUTOLOAD'}) {
$c->run_modes(
AUTOLOAD => sub {
my $self = shift;
return $self->error(
title => 'The requested page was not found.',
msg => "(The page tried was: ".$self->get_current_runmode.")"
)
});
}
}
use Params::Validate ':all';
sub error {
my $c = shift;
my %p = validate(@_, {
title => SCALAR,
msg => SCALAR,
# tmpl can be various types
tmpl => { default => 'error.html' },
});
# If a tmpl_path has been set, we want to ignore it, because it was most
# likely meant for the template itself, not for the error page.
# We are careful to put the value back how we found it after we are done with it here!
my @path_to_restore = $c->tmpl_path();
$c->tmpl_path('');
my $t = $c->load_tmpl($p{tmpl});
$c->tmpl_path(@path_to_restore);
$t->param(
title => $p{title},
msg => $p{msg},
);
return $t->output;
}
=head2 Example error.html
Here's a very basic example of an C<error.html> file to get you started.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title><!-- tmpl_var title escape=HTML --></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1><!-- tmpl_var title escape=HTML--></h1>
<p><!-- tmpl_var msg escape=HTML --></p>
</body>
</html>
We manage site-wide designs with Dreamweaver and keep a basic 'error.html' that
uses a generic Dreamweaver 'page.dwt' template with standard EditableRegion
names. That way, we can copy this error.html into a new Dreamweaver-managed
project and have the new design applied to it easily through Dreamweaver.
=head1 SUPPORT
Ask for help on the L<CGI::Application> mailing list. Report bugs and wishes
through the rt.cpan.org bug tracker.
=head1 AUTHOR
Mark Stosberg
CPAN ID: MARKSTOS
mark@summersault.com
=head1 COPYRIGHT
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=head1 SEE ALSO
perl(1).
=cut
1;
# The preceding line will help the module return a true value
( run in 1.615 second using v1.01-cache-2.11-cpan-5623c5533a1 )