line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::UnicodePictogramFallback::TypeCast; |
2
|
2
|
|
|
2
|
|
678413
|
use 5.008_001; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
92
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
81
|
|
5
|
2
|
|
|
2
|
|
2228
|
use utf8; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
11
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1979
|
use Plack::Util; |
|
2
|
|
|
|
|
36937
|
|
|
2
|
|
|
|
|
79
|
|
10
|
2
|
|
|
2
|
|
2336
|
use Plack::Middleware::UnicodePictogramFallback::TypeCast::EmoticonMap; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
87
|
|
11
|
2
|
|
|
2
|
|
2883
|
use Encode qw/encode_utf8 decode/; |
|
2
|
|
|
|
|
23534
|
|
|
2
|
|
|
|
|
201
|
|
12
|
2
|
|
|
2
|
|
2469
|
use Encode::JP::Mobile ':props'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Encode::JP::Mobile::UnicodeEmoji; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use parent 'Plack::Middleware'; |
16
|
|
|
|
|
|
|
use Plack::Util::Accessor qw( |
17
|
|
|
|
|
|
|
template |
18
|
|
|
|
|
|
|
fallback |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub prepare_app { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
die 'requires template' unless $self->template; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub call { |
28
|
|
|
|
|
|
|
my ($self, $env) = @_; |
29
|
|
|
|
|
|
|
my $res = $self->app->($env); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $h = Plack::Util::headers($res->[1]); |
32
|
|
|
|
|
|
|
return $res if $h->get('Content-Type') !~ m!^text/!; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->response_cb($res, sub { |
35
|
|
|
|
|
|
|
my $res = shift; |
36
|
|
|
|
|
|
|
return sub { |
37
|
|
|
|
|
|
|
my $chunk = shift; |
38
|
|
|
|
|
|
|
return unless defined $chunk; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->_filter($chunk); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _filter { |
46
|
|
|
|
|
|
|
my ($self, $html) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$html = decode('x-utf8-jp-mobile-unicode-emoji', $html); |
49
|
|
|
|
|
|
|
my $emoticon_map = Plack::Middleware::UnicodePictogramFallback::TypeCast::EmoticonMap::MAP; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $fallback = $self->fallback || sub {'〓'}; |
52
|
|
|
|
|
|
|
$html =~ s{(\p{InMobileJPPictograms})}{ |
53
|
|
|
|
|
|
|
my $char = $1; |
54
|
|
|
|
|
|
|
my $code = sprintf '%X', ord $char; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if (my $name = $emoticon_map->{$code}) { |
57
|
|
|
|
|
|
|
sprintf $self->template, $name, $char; |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
encode_utf8 $fallback->($char); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}ge; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
encode_utf8 $html; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |