Catalyst-Plugin-CustomErrorMessage

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.04  Tue Oct  6 12:49:20 2009
	- config "messsage" is now "message" (thanks to Oldřich Krůza)

0.03  Tue May 27 08:12:54 2008
	- calling view in an eval block
	- config "custome" is now "custom" (but previous also works)
	- migrated to the Module::Build so that build_requires can be set

0.02  Mon Oct  9 18:05:14 2007
	- added:
		__PACKAGE__->config->{'custome-error-messsage'}->{'content-type'}      = 'text/html; charset=utf-8';
		__PACKAGE__->config->{'custome-error-messsage'}->{'view-name'}         = 'TT';
		__PACKAGE__->config->{'custome-error-messsage'}->{'response-status'}   = 500;

0.01  Fri Oct  5 17:57:18 2007
	- initial version

README  view on Meta::CPAN

NAME
    Catalyst::Plugin::CustomErrorMessage - Catalyst plugin to have more
    "cute" error message.

SYNOPSIS
            use Catalyst qw( CustomErrorMessage );
        
            # optional (values in this example are the defaults)
            __PACKAGE__->config->{'custom-error-message'}->{'uri-for-not-found'} = '/';
            __PACKAGE__->config->{'custom-error-message'}->{'error-template'}    = 'error.tt2';
            __PACKAGE__->config->{'custom-error-message'}->{'content-type'}      = 'text/html; charset=utf-8';
            __PACKAGE__->config->{'custom-error-message'}->{'view-name'}         = 'TT';
            __PACKAGE__->config->{'custom-error-message'}->{'response-status'}   = 500;

DESCRIPTION
    You can use this module if you want to get rid of:

            (en) Please come back later
            (fr) SVP veuillez revenir plus tard
            (de) Bitte versuchen sie es spaeter nocheinmal
            (at) Konnten's bitt'schoen spaeter nochmal reinschauen

README  view on Meta::CPAN

            )

    $c->flash->{'finalize_error'} will be set to contain the error message.

    To set different view name configure:

            $c->config->{'custom-error-message'}->{'view-name'} = 'Mason';

    Content-type and response status can be configured via:

            $c->config->{'custom-error-message'}->{'content-type'}    = 'text/plain; charset=utf-8';
            $c->config->{'custom-error-message'}->{'response-status'} = 500;

AUTHOR
    Jozef Kutej - <jkutej@cpan.org>

COPYRIGHT AND LICENSE
    Copyright (C) 2006 by Jozef Kutej

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.8.4 or, at

lib/Catalyst/Plugin/CustomErrorMessage.pm  view on Meta::CPAN


Catalyst::Plugin::CustomErrorMessage - Catalyst plugin to have more "cute" error message.

=head1 SYNOPSIS

	use Catalyst qw( CustomErrorMessage );
	
	# optional (values in this example are the defaults)
	__PACKAGE__->config->{'custom-error-message'}->{'uri-for-not-found'} = '/';
	__PACKAGE__->config->{'custom-error-message'}->{'error-template'}    = 'error.tt2';
	__PACKAGE__->config->{'custom-error-message'}->{'content-type'}      = 'text/html; charset=utf-8';
	__PACKAGE__->config->{'custom-error-message'}->{'view-name'}         = 'TT';
	__PACKAGE__->config->{'custom-error-message'}->{'response-status'}   = 500;

=head1 DESCRIPTION

You can use this module if you want to get rid of:

	(en) Please come back later
	(fr) SVP veuillez revenir plus tard
	(de) Bitte versuchen sie es spaeter nocheinmal

lib/Catalyst/Plugin/CustomErrorMessage.pm  view on Meta::CPAN

	)

$c->flash->{'finalize_error'} will be set to contain the error message.

To set different view name configure:

	$c->config->{'custom-error-message'}->{'view-name'} = 'Mason';

Content-type and response status can be configured via: 

	$c->config->{'custom-error-message'}->{'content-type'}    = 'text/plain; charset=utf-8';
	$c->config->{'custom-error-message'}->{'response-status'} = 500;

=cut

sub finalize_error {
	my $c = shift;
	my $config = $c->config->{'custom-error-message'} || $c->config->{'custome-error-messsage'} || $c->config->{'custom-error-messsage'};
	
	# in debug mode return the original "page" 
	if ( $c->debug ) {

lib/Catalyst/Plugin/CustomErrorMessage.pm  view on Meta::CPAN

			'/'
		));

		return;
	}
	
	# render the template
	my $action_name = $c->action->reverse;
	$c->stash->{'finalize_error'} = $action_name.': '.$error;
	$c->response->content_type(
		$config->{'content-type'}
		||
		'text/html; charset=utf-8'
	);
	my $view_name = $config->{'view-name'} || 'TT';
	eval {
		$c->response->body($c->view($view_name)->render($c,
			$config->{'error-template'}
			||
			'error.tt2'
		));

t/01-Catalyst-Plugin-CustomErrorMessage.t  view on Meta::CPAN

		is($c->view_name, 'TT', 'default view is TT');
		is($c->view->template_name, 'error.tt2', 'default template is error.tt2');
		is($c->response->content_type, 'text/html; charset=utf-8', 'default content type is "text/html; charset=utf-8"');
	
		# setting non defaults
		my $view_name       = 'View';
		my $content_type    = 'text/plain; charset=utf-8';
		my $error_template  = 'my_error.tt2';
		my $response_status = 0;
		$c->config->{'custom-error-message'}->{'error-template'}    = $error_template;
		$c->config->{'custom-error-message'}->{'content-type'}      = $content_type;
		$c->config->{'custom-error-message'}->{'view-name'}         = $view_name;
		$c->config->{'custom-error-message'}->{'response-status'}   = $response_status;
	
		$c->finalize_error();
		ok($c->finalize_error_called, 'check if it was really called');
		
		is($c->view_name, $view_name, 'now view is "'.$view_name.'"');
		is($c->view->template_name, 'my_error.tt2', 'now template is my_error.tt2');
		is($c->response->content_type, $content_type, 'now content type is "'.$content_type.'"');
		is($c->response->status, $response_status, 'now response status is "'.$response_status.'"');



( run in 1.369 second using v1.01-cache-2.11-cpan-524268b4103 )