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
4 changed files
with
188 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,47 @@ | ||
package Kamui::Plugin::Mobile::DoCoMoGUIDFilter; | ||
use Kamui; | ||
use base 'Kamui::Plugin'; | ||
|
||
sub register_method { | ||
+{ | ||
docomo_guid_filter => sub { | ||
my $c = shift; | ||
Kamui::Plugin::Mobile::DoCoMoGUIDFilter::Backend->new($c); | ||
}, | ||
}; | ||
} | ||
|
||
package Kamui::Plugin::Mobile::DoCoMoGUIDFilter::Backend; | ||
use Kamui; | ||
use HTML::StickyQuery::DoCoMoGUID; | ||
|
||
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 ) ) | ||
&& $self->c->mobile_attribute->is_docomo | ||
&& $res->body ) | ||
{ | ||
my $body = $res->body; | ||
$res->body( | ||
sub { | ||
my $guid = HTML::StickyQuery::DoCoMoGUID->new; | ||
$guid->sticky( | ||
scalarref => \$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
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,131 @@ | ||
use t::Utils; | ||
use Test::Declare; | ||
use Kamui::Web::Context; | ||
use Mock::Web::Handler; | ||
|
||
plan tests => blocks; | ||
|
||
describe 'docomo guid filter tests' => run { | ||
|
||
init { | ||
my $plugins = [qw/MobileAttribute Mobile::DoCoMoGUIDFilter/]; | ||
Kamui::Web::Context->load_plugins($plugins); | ||
}; | ||
|
||
test 'carrier docomo test' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
HTTP_USER_AGENT => 'DoCoMo/2.0 T2101V(c100)', | ||
}; | ||
|
||
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('<a href="/">top</a>'); | ||
|
||
$c->docomo_guid_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '<a href="/?guid=ON">top</a>'; | ||
}; | ||
|
||
test 'carrier ez test' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
HTTP_USER_AGENT => 'KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1', | ||
}; | ||
|
||
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('<a href="/">top</a>'); | ||
|
||
$c->docomo_guid_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '<a href="/">top</a>'; | ||
}; | ||
|
||
test 'carrier softbank test' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
HTTP_USER_AGENT => 'SoftBank/1.0/910T/TJ001/SNXXXXXXXXX Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1', | ||
}; | ||
|
||
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('<a href="/">top</a>'); | ||
|
||
$c->docomo_guid_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '<a href="/">top</a>'; | ||
}; | ||
|
||
test 'carrier airh test' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
HTTP_USER_AGENT => 'Mozilla/3.0(DDIPOCKET;JRC/AH-J3001V,AH-J3002V/1.0/0100/c50)CNF/2.0', | ||
}; | ||
|
||
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('<a href="/">top</a>'); | ||
|
||
$c->docomo_guid_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '<a href="/">top</a>'; | ||
}; | ||
|
||
test 'carrier none_mobile test' => run { | ||
my $env = +{ | ||
REQUEST_METHOD => 'GET', | ||
SCRIPT_NAME => '/', | ||
HTTP_USER_AGENT => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)', | ||
}; | ||
|
||
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('<a href="/">top</a>'); | ||
|
||
$c->docomo_guid_filter; # call initializer. | ||
$c->finalize($res); | ||
|
||
is $res->body, '<a href="/">top</a>'; | ||
}; | ||
|
||
}; | ||
|