1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
use strict;
use warnings;
use Test::More;
BEGIN {
package TestApp::Exception;
$INC{'TestApp/Exception.pm'} = __FILE__;
sub new {
my ($class, $code, $headers, $body) = @_;
return bless +{res => [$code, $headers, $body]}, $class;
}
sub throw { die shift->new(@_) }
sub as_psgi {
my ($self, $env) = @_;
my ($code, $headers, $body) = @{$self->{res}};
return [$code, $headers, $body]; # for now
return sub {
my $responder = shift;
$responder->([$code, $headers, $body]);
};
}
package TestApp::Controller::Root;
$INC{'TestApp/Controller/Root.pm'} = __FILE__;
use Moose;
use MooseX::MethodAttributes;
extends 'Catalyst::Controller';
sub main :Path('') :Args(1) {
my ($self, $c, $arg) = @_;
$c->res->body('<h1>OK</h1>');
$c->res->content_type('text/html');
}
TestApp::Controller::Root->config(namespace => '');
}
{
package TestApp;
$INC{'TestApp.pm'} = __FILE__;
use Catalyst;
use TestApp::Exception;
sub handle_unicode_encoding_exception {
my ( $self, $param_value, $error_msg ) = @_;
TestApp::Exception->throw(
200, ['content-type'=>'text/plain'], ['Bad unicode data']);
}
__PACKAGE__->setup;
}
use Catalyst::Test 'TestApp';
{
my $res = request('/ok');
is ($res->status_line, "200 OK");
is ($res->content, '<h1>OK</h1>');
}
{
my $res = request('/%E2%C3%83%C6%92%C3%8');
is ($res->content, 'Bad unicode data');
}
done_testing;
#TestApp->to_app;
|