6 package TestApp::Exception;
7 $INC{'TestApp/Exception.pm'} = __FILE__;
10 my ($class, $code, $headers, $body) = @_;
11 return bless +{res => [$code, $headers, $body]}, $class;
14 sub throw { die shift->new(@_) }
17 my ($self, $env) = @_;
18 my ($code, $headers, $body) = @{$self->{res}};
20 return [$code, $headers, $body]; # for now
23 my $responder = shift;
24 $responder->([$code, $headers, $body]);
28 package TestApp::Controller::Root;
29 $INC{'TestApp/Controller/Root.pm'} = __FILE__;
32 use MooseX::MethodAttributes;
33 extends 'Catalyst::Controller';
35 sub main :Path('') :Args(1) {
36 my ($self, $c, $arg) = @_;
37 $c->res->body('<h1>OK</h1>');
38 $c->res->content_type('text/html');
41 TestApp::Controller::Root->config(namespace => '');
46 $INC{'TestApp.pm'} = __FILE__;
49 use TestApp::Exception;
51 sub handle_unicode_encoding_exception {
52 my ( $self, $param_value, $error_msg ) = @_;
53 TestApp::Exception->throw(
54 200, ['content-type'=>'text/plain'], ['Bad unicode data']);
61 use Catalyst::Test 'TestApp';
64 my $res = request('/ok');
65 is ($res->status_line, "200 OK");
66 is ($res->content, '<h1>OK</h1>');
70 my $res = request('/%E2%C3%83%C6%92%C3%8');
71 is ($res->content, 'Bad unicode data');