Filter/EntityReference.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 28 CC 3 SCAR 19.5
CC
3
Cov
0%
filter
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package HTML::MobileJp::Filter::EntityReference;
2 use Moose;
3  
4 with 'HTML::MobileJp::Filter::Role';
5  
6 has '+config' => (
7 default => sub {{
8 force => 0,
9 }},
10 );
11  
12 use Encode::JP::Mobile ':props';
13 use HTML::Entities::ConvertPictogramMobileJp;
14  
15 sub filter {
16 my ($self, $content) = @_;
17
18 if ($self->mobile_agent->is_non_mobile) {
19 if ($self->config->{force}) {
20 $content =~ s{(&\#x([A-Z0-9]+);)}{
21 my $code = $1;
22 my $char = chr hex $2;
23 $char =~ /\p{InMobileJPPictograms}/ ? $char : $code;
24 }ge;
25 }
26 } else {
27 $content = convert_pictogram_entities(
28 mobile_agent => $self->mobile_agent,
29 html => $content->stringfy,
30 );
31 }
32
33 $content;
34 }
35  
36 1;
37 __END__
38  
39 =encoding utf-8
40  
41 =head1 NAME
42  
43 HTML::MobileJp::Filter::EntityReference - i絵文字のコピペの代わりに実体参照で書いておける
44  
45 =head1 SYNOPSIS
46  
47 - module: EntityReference
48  
49 =head1 CONFIG AND DEFAULT VALUES
50  
51 force => 0,
52  
53 default ではこのフィルタは単純な HTML::Entities::ConvertPictogramMobileJp の
54 単純なラッパーで、PC の場合は何もしません。C<force> に 1 を指定すると
55 PC の場合も Unicode 16進数文字参照を Unicode へと置換するようになります。
56  
57 =head1 SEE ALSO
58  
59 L<HTML::Entities::ConvertPictogramMobileJp>
60  
61 =head1 AUTHOR
62  
63 Naoki Tomita E<lt>tomita@cpan.orgE<gt>
64  
65 =cut