-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package Kamui::Plugin::Mobile::EmojiFilter; | ||
use Kamui; | ||
use base 'Kamui::Plugin'; | ||
|
||
sub register_method { | ||
+{ | ||
mobile_emoji_filter => sub { | ||
my $c = shift; | ||
Kamui::Plugin::Mobile::EmojiFilter::Backend->new($c); | ||
}, | ||
}; | ||
} | ||
|
||
package Kamui::Plugin::Mobile::EmojiFilter::Backend; | ||
use Kamui; | ||
use Scalar::Util (); | ||
|
||
sub new { | ||
my ($class, $c) = @_; | ||
bless {c => $c}, $class; | ||
} | ||
|
||
sub c { $_[0]->{c} } | ||
|
||
sub finalize { | ||
my ($self, $res) = @_; | ||
|
||
if ( $res && $res->status == 200 | ||
&& $res->content_type =~ /html/ | ||
&& not( Scalar::Util::blessed( $res->body ) ) | ||
&& $res->body ) | ||
{ | ||
(my $body = $res->body) =~ s{ \{ (?:emoji|u): ([0-9A-F]{4}) \} }{ pack('U*', hex $1) }geixms; | ||
$res->body($body); | ||
} | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use t::Utils; | ||
use Test::Declare; | ||
use Kamui::Web::Context; | ||
use Mock::Web::Handler; | ||
|
||
plan tests => blocks; | ||
|
||
describe 'emoji filter tests' => run { | ||
init { | ||
my $plugins = [qw/Mobile::EmojiFilter/]; | ||
Kamui::Web::Context->load_plugins($plugins); | ||
}; | ||
|
||
test 'emoji filter' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
}; | ||
|
||
my $c = Kamui::Web::Context->new( | ||
env => $env, | ||
app => 'Mock::Web::Handler', | ||
); | ||
|
||
my $res = $c->res; | ||
$res->status('200'); | ||
$res->headers([ 'Content-Type' => 'text/html' ]); | ||
$res->body('{emoji:E21E}'); | ||
|
||
$c->mobile_emoji_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, "\x{e21e}"; | ||
}; | ||
|
||
test 'emoji filter' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
}; | ||
|
||
my $c = Kamui::Web::Context->new( | ||
env => $env, | ||
app => 'Mock::Web::Handler', | ||
); | ||
|
||
my $res = $c->res; | ||
$res->status('200'); | ||
$res->headers([ 'Content-Type' => 'text/html' ]); | ||
$res->body('{emozi:E21E}'); | ||
|
||
$c->mobile_emoji_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '{emozi:E21E}'; | ||
}; | ||
}; | ||
|