Catalyst-Plugin-CustomErrorMessage-0.06000755001752001753 011442143374 17673 5ustar00jozefjozef000000000000Catalyst-Plugin-CustomErrorMessage-0.06/Build.PL000444001752001753 151211442143374 21323 0ustar00jozefjozef000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Catalyst::Plugin::CustomErrorMessage', license => 'perl', dist_author => 'Jozef Kutej ', dist_version_from => 'lib/Catalyst/Plugin/CustomErrorMessage.pm', requires => { 'Class::Data::Inheritable' => 0, 'HTML::Entities' => 0, 'URI::Escape' => 0, 'MRO::Compat' => 0, }, build_requires => { 'Test::More' => 0, 'Class::Accessor::Fast' => 0, 'Carp::Clan' => 0, }, add_to_cleanup => [ 'Catalyst-Plugin-CustomErrorMessage-*' ], create_makefile_pl => 'traditional', sign => 1, create_readme => 1, ); $builder->create_build_script(); Catalyst-Plugin-CustomErrorMessage-0.06/MANIFEST000444001752001753 34011442143374 21136 0ustar00jozefjozef000000000000Build.PL Changes lib/Catalyst/Plugin/CustomErrorMessage.pm Makefile.PL MANIFEST META.yml README t/00-distribution.t t/01-Catalyst-Plugin-CustomErrorMessage.t t/pod-coverage.t t/pod.t SIGNATURE Added here by Module::Build Catalyst-Plugin-CustomErrorMessage-0.06/META.yml000444001752001753 127311442143374 21304 0ustar00jozefjozef000000000000--- abstract: "Catalyst plugin to have more \"cute\" error message." author: - 'Jozef Kutej ' build_requires: Carp::Clan: 0 Class::Accessor::Fast: 0 Test::More: 0 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3607' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Catalyst-Plugin-CustomErrorMessage provides: Catalyst::Plugin::CustomErrorMessage: file: lib/Catalyst/Plugin/CustomErrorMessage.pm version: 0.06 requires: Class::Data::Inheritable: 0 HTML::Entities: 0 MRO::Compat: 0 URI::Escape: 0 resources: license: http://dev.perl.org/licenses/ version: 0.06 Catalyst-Plugin-CustomErrorMessage-0.06/README000444001752001753 513211442143374 20711 0ustar00jozefjozef000000000000NAME 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 (no) Vennligst prov igjen senere (dk) Venligst prov igen senere (pl) Prosze sprobowac pozniej What it does is that it inherites finalize_error to $c object. See finalize_error() function. FUNCTIONS finalize_error In debug mode this function is skipped and user sees the original Catalyst error page in debug mode. In "production" (non debug) mode it will return page with template set in $c->config->{'custom-error-message'}->{'error-template'} || 'error.tt2' $c->stash->{'finalize_error'} will be set to contain the error message. For non existing resources (like misspelled url-s) if will do http redirect to $c->uri_for( $c->config->{'custom-error-message'}->{'uri-for-not-found'} || '/' ) $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 - 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 your option, any later version of Perl 5 you may have available. Catalyst-Plugin-CustomErrorMessage-0.06/SIGNATURE000644001752001753 261511442143374 21322 0ustar00jozefjozef000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.63. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 1333c39593e8c966b8d9500a3ea14938d597a99a Build.PL SHA1 0b8ff9eaea44af586118961920df013c4c4b6748 Changes SHA1 10b96b8e8b56b0fb54f1701507b6c3c9baee8fc6 MANIFEST SHA1 cfca6be59b10b8605b9c40b0bd36f7d25de4eec8 META.yml SHA1 8a0f1f9505bbab904a5078c5d5fc2d62cb8a5b11 Makefile.PL SHA1 7de54986af9d60c2212b49b396dc461c11d433cc README SHA1 b88b595507dba8f09158cd619b3e4c1bc2651004 lib/Catalyst/Plugin/CustomErrorMessage.pm SHA1 41533fbd463e42d2ecf1e119eca910c16809d13e t/00-distribution.t SHA1 24ccea4f5d8ae7d1750ce295b72e9bd10fa781e0 t/01-Catalyst-Plugin-CustomErrorMessage.t SHA1 0b1c5a2d59be6bfa7d60c64cd964fea6a0331705 t/pod-coverage.t SHA1 640935336dc1123c0069bcf5432bcaedc2cf22d3 t/pod.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkyIxvwACgkQC0OgUPgL2SekqACfcScCFxPgf4gGuPxP4znWfR+w KvoAnj2lh4Ctz6W4J5CIevBfLKOAHkCJ =6JvD -----END PGP SIGNATURE----- Catalyst-Plugin-CustomErrorMessage-0.06/Changes000444001752001753 164011442143374 21324 0ustar00jozefjozef000000000000Revision history for Perl extension Catalyst::Plugin::CustomErrorMessage. 0.06 Thu, 09 Sep 2010 13:35:31 +0200 - removed unneeded dependency 0.05 Tue, 07 Sep 2010 16:58:24 +0200 - #60723 replaced 'use NEXT;' by 'use MRO::Compat;' (thanks to Sven - NIERLEIN@cpan.org) 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 Catalyst-Plugin-CustomErrorMessage-0.06/Makefile.PL000444001752001753 137111442143374 22004 0ustar00jozefjozef000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.3607 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Catalyst::Plugin::CustomErrorMessage', 'VERSION_FROM' => 'lib/Catalyst/Plugin/CustomErrorMessage.pm', 'PREREQ_PM' => { 'Carp::Clan' => 0, 'Class::Accessor::Fast' => 0, 'Class::Data::Inheritable' => 0, 'HTML::Entities' => 0, 'MRO::Compat' => 0, 'Test::More' => 0, 'URI::Escape' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Catalyst-Plugin-CustomErrorMessage-0.06/lib000755001752001753 011442143374 20441 5ustar00jozefjozef000000000000Catalyst-Plugin-CustomErrorMessage-0.06/lib/Catalyst000755001752001753 011442143374 22225 5ustar00jozefjozef000000000000Catalyst-Plugin-CustomErrorMessage-0.06/lib/Catalyst/Plugin000755001752001753 011442143374 23463 5ustar00jozefjozef000000000000Catalyst-Plugin-CustomErrorMessage-0.06/lib/Catalyst/Plugin/CustomErrorMessage.pm000444001752001753 752411442143374 27757 0ustar00jozefjozef000000000000package Catalyst::Plugin::CustomErrorMessage; =head1 NAME 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 (at) Konnten's bitt'schoen spaeter nochmal reinschauen (no) Vennligst prov igjen senere (dk) Venligst prov igen senere (pl) Prosze sprobowac pozniej What it does is that it inherites finalize_error to $c object. See finalize_error() function. =cut use base qw{ Class::Data::Inheritable }; use HTML::Entities; use URI::Escape qw{ uri_escape_utf8 }; use MRO::Compat; use strict; use warnings; our $VERSION = "0.06"; =head1 FUNCTIONS =head2 finalize_error In debug mode this function is skipped and user sees the original Catalyst error page in debug mode. In "production" (non debug) mode it will return page with template set in $c->config->{'custom-error-message'}->{'error-template'} || 'error.tt2' $c->stash->{'finalize_error'} will be set to contain the error message. For non existing resources (like misspelled url-s) if will do http redirect to $c->uri_for( $c->config->{'custom-error-message'}->{'uri-for-not-found'} || '/' ) $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 ) { $c->maybe::next::method; return; } # create error string out of error array my $error = join '
', map { encode_entities($_) } @{ $c->error }; $error ||= 'No output'; # for wrong url that has no action associated do redirect if (not defined $c->action) { $c->flash->{'finalize_error'} = $error; $c->_save_flash(); # hack but must be called otherwise the flash data will be lost $c->response->redirect($c->uri_for( $config->{'uri-for-not-found'} || '/' )); 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' )); }; if ($@) { $c->log->error($@); $c->maybe::next::method; } my $response_status = $config->{'response-status'}; $response_status = 500 if not defined $response_status; $c->response->status($response_status); } 1; =head1 AUTHOR Jozef Kutej - Ejkutej@cpan.orgE =head1 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 your option, any later version of Perl 5 you may have available. =cut Catalyst-Plugin-CustomErrorMessage-0.06/t000755001752001753 011442143374 20136 5ustar00jozefjozef000000000000Catalyst-Plugin-CustomErrorMessage-0.06/t/00-distribution.t000444001752001753 17211442143374 23374 0ustar00jozefjozef000000000000use Test::More; eval 'use Test::Distribution not => "sig"'; plan( skip_all => 'Test::Distribution not installed') if $@; Catalyst-Plugin-CustomErrorMessage-0.06/t/01-Catalyst-Plugin-CustomErrorMessage.t000444001752001753 1675511442143374 27543 0ustar00jozefjozef000000000000#!/usr/bin/perl use strict; use warnings; #use Test::More 'no_plan'; use Test::More 'tests' => 24; use English; BEGIN { use_ok('Catalyst::Plugin::CustomErrorMessage') or exit }; exit main(); sub main { can_ok('Catalyst::Plugin::CustomErrorMessage', 'finalize_error'); SKIP: { eval "use base 'Class::Accessor::Fast'"; skip 'no "Class::Accessor::Fast" installed skipping fake Catalyst tests.', 22 if $EVAL_ERROR; my $c; diag '> in debug mode'; $c = MyCatalyst->new( 'debug' => 1, 'error' => [ 'error message1', 'error message2', ], ); $c->finalize_error(); ok($c->finalize_error_called, 'check if finalize_error() was really called'); ok(!$c->finalize_error_called, 'check internal finalize_error()'); is($c->flash->{'finalize_error'}, undef, 'flash empty'); is($c->response->body, undef, 'response body empty'); diag '> no action set tests'; $c = MyCatalyst->new( 'error' => [ 'error message1', 'error message2', ], ); $c->finalize_error(); ok($c->finalize_error_called, 'check if it was really called'); is($c->response->redirect, '/', 'default redirect is "/"'); is($c->flash->{'finalize_error'}, 'error message1
error message2', 'check error message in flash'); # setting non defaults $c->config->{'custom-error-message'}->{'uri-for-not-found'} = '/custom'; $c->finalize_error(); ok($c->finalize_error_called, 'check if it was really called'); is($c->response->redirect, '/custom', 'config redirect is "/custom"'); diag '> action set tests'; $c = MyCatalyst->new( 'action' => MyCatalyst::Action->new(), 'error' => [ 'error message1', 'error message2', ], ); $c->finalize_error(); ok($c->finalize_error_called, 'check if it was really called'); 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.'"'); # catching errors in the view $c->config({}); $c->config->{'custom-error-message'}->{'view-name'} = 'BrokenView'; $c->flash->{'finalize_error'} = undef; $c->response->body(undef); $c->finalize_error(); ok($c->finalize_error_called, 'check if it was really called'); is($c->flash->{'finalize_error'}, undef, 'flash empty'); is($c->response->body, undef, 'response body empty'); like($c->log->error, qr{non_existing_function}, 'error is logged'); } return 0; } =head1 MyCatalyst Pseudo Catalyst object for testing. =cut package MyCatalyst; use strict; use warnings; use English; use Carp::Clan; use MRO::Compat; use base 'Catalyst::Plugin::CustomErrorMessage'; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ view_name config debug error action response flash stash _save_flash }); } } sub new { my $class = shift; my %args = @_; my $self = $class->next::method(\%args); $self->response(MyCatalyst::Response->new()); $self->flash({}) if not defined $self->flash; $self->stash({}) if not defined $self->stash; $self->config({}) if not defined $self->config; return $self; } sub finalize_error { my $self = shift; $self->next::method; $self->finalize_error_called(1); } sub finalize_error_called { my $self = shift; # get if (@_ == 0) { if ($self->{'finalize_error_called'}) { $self->{'finalize_error_called'} = 0; return 1; } else { return 0; } } #set else { $self->{'finalize_error_called'} = shift; return; } } sub view { my $self = shift; my $view_name = shift; if (defined $view_name) { $self->view_name($view_name); $view_name = 'MyCatalyst::'.$view_name; $self->{'last_view_object'} = $view_name->new(); } return $self->{'last_view_object'}; } sub uri_for { my $self = shift; my $path = shift; return $path; } sub log { my $self = shift; return $self->logger; } sub logger { my $self = shift; $self->{'logger'} = MyCatalyst::Logger->new() if (not $self->{'logger'}); return $self->{'logger'}; } 1; =head1 MyCatalyst::Logger Simple logger for MyCatalyst. =cut package MyCatalyst::Logger; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ fatal error warn info debug }); } } 1; =head1 MyCatalyst::View Custom catalyst view for testing; =cut package MyCatalyst::View; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ template_name }); } } sub render { my $self = shift; my $c = shift; my $template_name = shift; croak 'pass template name' if not defined $template_name; $self->template_name($template_name); } 1; =head1 MyCatalyst::TT Custom catalyst view for testing; =cut package MyCatalyst::TT; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ template_name }); } } sub render { my $self = shift; my $c = shift; my $template_name = shift; croak 'pass template name' if not defined $template_name; $self->template_name($template_name); } 1; =head1 MyCatalyst::BrokenView Custom catalyst view for testing; =cut package MyCatalyst::BrokenView; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ template_name }); } } sub render { my $self = shift; my $c = shift; my $template_name = shift; croak 'pass template name' if not defined $template_name; $self->non_existing_function; } 1; =head1 MyCatalyst::Response Custom catalyst response for testing; =cut package MyCatalyst::Response; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ content_type body redirect status }); } } 1; =head1 MyCatalyst::action Custom catalyst action for testing; =cut package MyCatalyst::Action; use strict; use warnings; use English; use Carp::Clan; BEGIN { eval "use base 'Class::Accessor::Fast'"; if (not $EVAL_ERROR) { __PACKAGE__->mk_accessors(qw{ reverse }); } } sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->reverse('MyReverse') if not defined $self->reverse; return $self; } 1; Catalyst-Plugin-CustomErrorMessage-0.06/t/pod-coverage.t000444001752001753 104711442143374 23035 0ustar00jozefjozef000000000000use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok(); Catalyst-Plugin-CustomErrorMessage-0.06/t/pod.t000444001752001753 35011442143374 21220 0ustar00jozefjozef000000000000#!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok();