File: Root.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (81 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (4)
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
77
78
79
80
81
package TestAppUnicode::Controller::Root;
use strict;
use warnings;
use utf8;

__PACKAGE__->config(namespace => q{});

use base 'Catalyst::Controller';

sub main :Path('') {
    my ($self, $ctx, $charset) = @_;
    my $content_type = 'text/html';
    if ($ctx->stash->{charset}) {
        $content_type .= ";charset=" . $ctx->stash->{charset};
    }
    $ctx->res->body('<h1>It works</h1>');
    $ctx->res->content_type($content_type);
}

sub unicode_no_enc :Local {
    my ($self, $c) = @_;
    my $data = "ほげ"; # hoge!
    utf8::encode($data);
    $c->response->body($data);
    $c->res->content_type('text/plain');
    $c->encoding(undef);
}

sub unicode :Local {
    my ($self, $c) = @_;
    my $data = "ほげ"; # hoge!
    $c->response->body($data); # should be decoded
    $c->res->content_type('text/plain');
}

sub not_unicode :Local {
    my ($self, $c) = @_;
    my $data = "\x{1234}\x{5678}";
    utf8::encode($data); # DO NOT WANT unicode
    $c->response->body($data); # just some octets
    $c->res->content_type('text/plain');
    $c->encoding(undef);
}

sub latin1 :Local {
  my ($self, $c) = @_;

  $c->res->content_type('text/plain');
  $c->response->body('LATIN SMALL LETTER E WITH ACUTE: é');
}

sub file :Local {
    my ($self, $c) = @_;
    close *STDERR; # i am evil.
    open my $test_file, '<', \"this is a test";
    $c->response->body($test_file);
}

sub capture : Chained('/') CaptureArgs(1) {}

sub decode_capture : Chained('capture') PathPart('') Args(0) {
    my ( $self, $c, $cap_arg ) = @_;
    $c->forward('main');
}

sub capture_charset : Chained('/') Args(1) {
    my ( $self, $c, $cap_arg ) = @_;
    $c->stash(charset => $cap_arg);
    $c->forward('main');
}

sub shift_jis :Local {
    my ($self, $c) = @_;
    my $data = "ほげ"; # hoge!
    $c->response->body($data); # should be decoded
    $c->res->content_type('text/plain; charset=Shift_JIS');
    $c->encoding("Shift_JIS");
}

1;