Navigation Menu

Skip to content

Commit

Permalink
add docomo guid filter plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekokak committed Oct 24, 2009
1 parent 79d7b52 commit 7cf40b4
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 1 deletion.
9 changes: 9 additions & 0 deletions TODO
Expand Up @@ -8,3 +8,12 @@ todo:
- redirect_301もつくるか
- authももう少し考える
- containerが長いaliasもきりたいな
- container系でapiとかformとかでnamespaceを省略させるのはいいがもっと汎用的にしたい
-- registerの拡張でregist_namespaceみたいなので拡張してしまうか?

- docomo css filter
- # docomo guid filter
- encode mobilejp
- emoji filter
- Plugin::Mobileにしてみるか

47 changes: 47 additions & 0 deletions lib/Kamui/Plugin/Mobile/DoCoMoGUIDFilter.pm
@@ -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;

2 changes: 1 addition & 1 deletion lib/Kamui/Plugin/MobileAttribute.pm
@@ -1,7 +1,7 @@
package Kamui::Plugin::MobileAttribute;
use Kamui;
use base 'Kamui::Plugin';
use HTTP::MobileAttribute;
use HTTP::MobileAttribute plugins => [qw/Core IS/];

sub register_method {
+{
Expand Down
131 changes: 131 additions & 0 deletions t/030_plugin/mobile/docomo_guid_filter.t
@@ -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>';
};

};

0 comments on commit 7cf40b4

Please sign in to comment.