Egg-Release
view release on metacpan or search on metacpan
lib/Egg/Plugin/Response/Redirect.pm view on Meta::CPAN
use warnings;
our $VERSION= '3.01';
{
no warnings 'redefine';
*Egg::Response::handler::redirect_body= sub { shift->e->redirect_body(@_) };
};
sub _setup {
my($e)= @_;
my $conf = $e->config->{plugin_response_redirect} ||= {};
my $style= $conf->{style} ||= {};
$conf->{default_url} ||= '/';
$conf->{default_wait} ||= 0;
$conf->{default_msg} ||= 'Processing was completed.';
$style->{body}
||= q{ background:#FFEDBB; text-align:center; };
$style->{h1}
||= q{ font:bold 20px sans-serif; margin:0px; margin-left:0px; };
$style->{div}
||= q{ background:#FFF7ED; padding:10px; margin:50px;}
. q{ font:normal 12px sans-serif; border:#D15C24 solid 3px;}
. q{ text-align:left; };
$e->next::method;
}
sub redirect_body {
my $e= shift;
$e->finished('200 OK');
$e->response->body($e->__redirect_body(@_));
}
sub __redirect_body {
my $e= shift;
my($res, $c)= ($e->response, $e->config);
my $cr = $c->{plugin_response_redirect};
my $style = $cr->{style};
my $url = shift || $cr->{default_url};
my $msg = shift || $cr->{default_msg};
my $attr = $_[0] ? (ref($_[0]) ? $_[0]: {@_}): {};
my $wait = defined($attr->{wait}) ? $attr->{wait}: $cr->{default_wait};
my $onload= $attr->{onload} ? qq{ onload="$attr->{onload}"}: "";
my $more = $attr->{more} || "";
my $alert = ! $attr->{alert} ? "": <<END_SCRIPT;
<script type="text/javascript"><!-- //
window.onload= alert('${msg}');
// --></script>
END_SCRIPT
my $body_style= $attr->{body_style} || $style->{body};
my $div_style = $attr->{div_style} || $style->{div};
my $h1_style = $attr->{h1_style} || $style->{h1};
my $clang = $res->content_language($c->{content_language} || 'en');
my $ctype = $res->content_type($c->{content_type} || 'text/html');
<<END_OF_HTML;
<!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="${clang}">
<head>
<meta http-equiv="content-language" content="${clang}" />
<meta http-equiv="Content-Type" content="${ctype}" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="refresh" content="${wait};url=${url}" />
${alert}
<style type="text/css">
body { ${body_style} }
div { ${div_style} }
h1 { ${h1_style} }
</style>
</head>
<body${onload}>
<div>
<h1>${msg}</h1>
<a href="${url}">- Please click here when forwarding fails...</a>
</div>
${more}
</body>
</html>
END_OF_HTML
}
1;
__END__
=head1 NAME
Egg::Plugin::Response::Redirect - Output of redirect screen etc.
=head1 SYNOPSIS
use Egg qw/ Response::Redirect /;
__PACKAGE__->egg_startup(
plugin_redirect => {
default_url => '/',
default_wait => 0,
default_msg => 'Processing was completed.',
style => {
body => ' ..... ',
h1 => ' ..... ',
div => ' ..... ',
},
},
);
# redirect screen is output and processing is ended.
$e->redirect_body('/hoge_page', 'complete ok.', alert => 1 );
# The HTML source of redirect screen is acquired.
my $html= $e->redirect_body_source('/hoge_page', 'complete ok.', alert => 1 );
=head1 DESCRIPTION
It is a plugin that outputs the redirect screen.
( run in 1.612 second using v1.01-cache-2.11-cpan-13bb782fe5a )