HTML::MobileJp::Filter::EntityReference - i絵文字のコピペの代わりに実体参照で書いておける


HTML-MobileJp-Filter documentation Contained in the HTML-MobileJp-Filter distribution.

Index


Code Index:

NAME

Top

HTML::MobileJp::Filter::EntityReference - i絵文字のコピペの代わりに実体参照で書いておける

SYNOPSIS

Top

  - module: EntityReference

CONFIG AND DEFAULT VALUES

Top

  force => 0,

default ではこのフィルタは単純な HTML::Entities::ConvertPictogramMobileJp の 単純なラッパーで、PC の場合は何もしません。force に 1 を指定すると PC の場合も Unicode 16進数文字参照を Unicode へと置換するようになります。

SEE ALSO

Top

HTML::Entities::ConvertPictogramMobileJp

AUTHOR

Top

Naoki Tomita <tomita@cpan.org>


HTML-MobileJp-Filter documentation Contained in the HTML-MobileJp-Filter distribution.

package HTML::MobileJp::Filter::EntityReference;
use Any::Moose;

with 'HTML::MobileJp::Filter::Role';

has '+config' => (
    default => sub {{
        force => 0,
    }},
);

use Encode::JP::Mobile ':props';
use HTML::Entities::ConvertPictogramMobileJp;

sub filter {
    my ($self, $content) = @_;
    
    if ($self->mobile_agent->is_non_mobile) {
        if ($self->config->{force}) {
            $content =~ s{(&\#x([A-Z0-9]+);)}{
                                my $code = $1;
                                my $char = chr hex $2;
                                $char =~ /\p{InMobileJPPictograms}/ ? $char : $code;
                        }ge;
        }
    } else {
        $content = convert_pictogram_entities(
            mobile_agent => $self->mobile_agent,
            html         => $content->stringfy,
        );
    }
    
    $content;
}

__PACKAGE__->meta->make_immutable;

1;
__END__