| 1 | package HTML::MobileJp::Filter::EntityReference; | ||
| 2 | use Any::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 | __PACKAGE__->meta->make_immutable; | ||
| 37 | |||
| 38 | 1; | ||
| 39 | __END__ |