drop IO::Scalar prereq
[catagits/Catalyst-Runtime.git] / t / lib / TestAppUnicode / Controller / Root.pm
CommitLineData
55046410 1package TestAppUnicode::Controller::Root;
2use strict;
3use warnings;
4use utf8;
5
6__PACKAGE__->config(namespace => q{});
7
8use base 'Catalyst::Controller';
9
88e5a8b0 10sub main :Path('') {
55046410 11 my ($self, $ctx, $charset) = @_;
12 my $content_type = 'text/html';
13 if ($ctx->stash->{charset}) {
14 $content_type .= ";charset=" . $ctx->stash->{charset};
15 }
16 $ctx->res->body('<h1>It works</h1>');
17 $ctx->res->content_type($content_type);
18}
19
20sub unicode_no_enc :Local {
21 my ($self, $c) = @_;
22 my $data = "ほげ"; # hoge!
23 utf8::encode($data);
24 $c->response->body($data);
25 $c->res->content_type('text/plain');
26 $c->encoding(undef);
27}
28
29sub unicode :Local {
30 my ($self, $c) = @_;
31 my $data = "ほげ"; # hoge!
32 $c->response->body($data); # should be decoded
33 $c->res->content_type('text/plain');
34}
35
36sub not_unicode :Local {
37 my ($self, $c) = @_;
38 my $data = "\x{1234}\x{5678}";
39 utf8::encode($data); # DO NOT WANT unicode
40 $c->response->body($data); # just some octets
41 $c->res->content_type('text/plain');
42 $c->encoding(undef);
43}
44
45sub latin1 :Local {
46 my ($self, $c) = @_;
47
48 $c->res->content_type('text/plain');
49 $c->response->body('LATIN SMALL LETTER E WITH ACUTE: é');
50}
51
52sub file :Local {
53 my ($self, $c) = @_;
54 close *STDERR; # i am evil.
1d285816 55 open my $test_file, '<', \"this is a test";
56 $c->response->body($test_file);
55046410 57}
58
59sub capture : Chained('/') CaptureArgs(1) {}
60
61sub decode_capture : Chained('capture') PathPart('') Args(0) {
62 my ( $self, $c, $cap_arg ) = @_;
63 $c->forward('main');
64}
65
66sub capture_charset : Chained('/') Args(1) {
67 my ( $self, $c, $cap_arg ) = @_;
68 $c->stash(charset => $cap_arg);
69 $c->forward('main');
70}
71
72sub shift_jis :Local {
73 my ($self, $c) = @_;
74 my $data = "ほげ"; # hoge!
75 $c->response->body($data); # should be decoded
76 $c->res->content_type('text/plain; charset=Shift_JIS');
77 $c->encoding("Shift_JIS");
78}
79
801;
81