line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::TT::ForceUTF8; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20491
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Catalyst::View::TT'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1953
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1000295
|
use Template::Provider::Encoding 0.09; |
|
1
|
|
|
|
|
15191
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
1019
|
use Template::Stash::ForceUTF8; |
|
1
|
|
|
|
|
34672
|
|
|
1
|
|
|
|
|
34
|
|
11
|
1
|
|
|
1
|
|
11
|
use Path::Class; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
701
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @PROVIDER_CONFIG_KEYS = qw/ |
14
|
|
|
|
|
|
|
INCLUDE_PATH |
15
|
|
|
|
|
|
|
DEFAULT_ENCODING |
16
|
|
|
|
|
|
|
COMPILE_DIR |
17
|
|
|
|
|
|
|
COMPILE_EXT |
18
|
|
|
|
|
|
|
EVAL_PERL |
19
|
|
|
|
|
|
|
PARSER |
20
|
|
|
|
|
|
|
PRE_CHOMP |
21
|
|
|
|
|
|
|
POST_CHOMP |
22
|
|
|
|
|
|
|
/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# XXX: this is but a copy from View::TT. |
25
|
|
|
|
|
|
|
# But this subroutine isn't class or instance method, |
26
|
|
|
|
|
|
|
# so this module couldn't inherit from View::TT |
27
|
|
|
|
|
|
|
sub _coerce_paths { |
28
|
0
|
|
|
0
|
|
|
my ($paths, $dlim) = @_; |
29
|
0
|
0
|
|
|
|
|
return () if (!$paths); |
30
|
0
|
0
|
|
|
|
|
return @{$paths} if (ref $paths eq 'ARRAY'); |
|
0
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
unless (defined $dlim) { |
32
|
0
|
0
|
|
|
|
|
$dlim = ($^O eq 'MSWin32') ? ':(?!\\/)' : ':'; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
return split(/$dlim/, $paths); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
0
|
|
|
0
|
1
|
|
my ( $class, $c, $arguments ) = @_; |
39
|
0
|
|
|
|
|
|
my $config = {%{$class->config}, %{$arguments}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# XXX: copied from View::TT |
42
|
0
|
0
|
|
|
|
|
if (!(ref $config->{INCLUDE_PATH} eq 'ARRAY')) { |
43
|
0
|
|
|
|
|
|
my $delim = $config->{DELIMITER}; |
44
|
|
|
|
|
|
|
my @include_path |
45
|
0
|
|
|
|
|
|
= _coerce_paths($config->{INCLUDE_PATH}, $delim); |
46
|
0
|
0
|
|
|
|
|
if ( !@include_path ) { |
47
|
0
|
|
|
|
|
|
my $root = $c->config->{root}; |
48
|
0
|
|
|
|
|
|
my $base = Path::Class::dir($root, 'base'); |
49
|
0
|
|
|
|
|
|
@include_path = ("$root", "$base"); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
$config->{INCLUDE_PATH} = \@include_path; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my %args = map { ($_, $config->{$_}) } |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
grep { exists $config->{$_} } |
56
|
|
|
|
|
|
|
@PROVIDER_CONFIG_KEYS; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$class->config->{PROVIDERS} = [ { |
59
|
|
|
|
|
|
|
name => 'Encoding', |
60
|
|
|
|
|
|
|
args => \%args, |
61
|
|
|
|
|
|
|
copy_config => [qw(INCLUDE_PATH)], |
62
|
|
|
|
|
|
|
}, ]; |
63
|
0
|
|
|
|
|
|
$class->config->{STASH} = Template::Stash::ForceUTF8->new; |
64
|
0
|
|
0
|
|
|
|
$class->config->{STRICT_CONTENT_TYPE} ||= 0; |
65
|
0
|
|
|
|
|
|
$class->SUPER::new($c, $arguments); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub process { |
69
|
0
|
|
|
0
|
1
|
|
my ($self, $c) = @_; |
70
|
0
|
0
|
|
|
|
|
unless ($c->res->content_type) { |
71
|
0
|
0
|
|
|
|
|
if ($self->config->{STRICT_CONTENT_TYPE}) { |
72
|
0
|
|
0
|
|
|
|
my $agent = $c->req->user_agent || ''; |
73
|
0
|
0
|
|
|
|
|
$c->res->content_type( |
74
|
|
|
|
|
|
|
$agent =~ /MSIE/ |
75
|
|
|
|
|
|
|
? 'text/html; charset=utf-8' |
76
|
|
|
|
|
|
|
: 'application/xhtml+xml; charset=utf-8' |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
$self->SUPER::process($c); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Catalyst::View::TT::ForceUTF8 - (DEPRECATED) Template View Class with utf8 encoding |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
package MyApp::View::TT; |
90
|
|
|
|
|
|
|
use base 'Catalyst::View::TT::ForceUTF8'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPITON |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Template View Class with utf8 encoding. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This allows you to prevent publishing garbled result. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Now this module is deprecated. |
99
|
|
|
|
|
|
|
http://dev.catalystframework.org/wiki/gettingstarted/tutorialsandhowtos/using_unicode |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 CONFIG |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__PACKAGE__->config( |
104
|
|
|
|
|
|
|
INCLUDE_PATH => [..], |
105
|
|
|
|
|
|
|
TIMER => 0, |
106
|
|
|
|
|
|
|
... # and other View::TT's configuration. |
107
|
|
|
|
|
|
|
STRICT_CONTENT_TYPE => 1, |
108
|
|
|
|
|
|
|
DEFAULT_ENCODING => 'utf-8', |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item DEFAULT_ENCODING |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
'utf-8' is set by default. See more detail L<Template::Provider::Encoding>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item CONTENT TYPE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
When you set *STRICT_CONTENT_TYPE* configuration, |
121
|
|
|
|
|
|
|
It automatically set content-type 'application/xhtml+xml; charset=utf-8' |
122
|
|
|
|
|
|
|
for browsers except MSIE. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L<Catalyst::View::TT>, L<Template::Provider::Encoding> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Lyo Kato, C<lyo.kato@gmail.com> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 LISENCE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The library if free software; you can redistribute it and/or modify |
137
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |