Changeset 17814 for lang/perl

Show
Ignore:
Timestamp:
08/18/08 01:37:22 (6 years ago)
Author:
tokuhirom
Message:

do not use H::E:Compat

Location:
lang/perl/mobirc/trunk
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/mobirc/trunk/Makefile.PL

    r17797 r17814  
    1111# http-engine 
    1212requires 'HTTP::Engine'         => '0.0.13'; # TODO: depend to recent version 
    13 requires 'HTTP::Engine::Compat' => '0.0.1'; 
    1413 
    1514# poe 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Plugin/Component/HTTPD.pm

    r17622 r17814  
    88 
    99use HTTP::Engine; 
    10 use HTTP::Engine::Compat middlewares => [ 
    11     qw/ 
    12         +App::Mobirc::Web::Middleware::Encoding 
    13         +App::Mobirc::Web::Middleware::MobileAgent 
    14     / 
    15 ]; 
     10use App::Mobirc::Web::Middleware::Encoding; 
     11use App::Mobirc::Web::Middleware::MobileAgent; 
    1612 
    1713has address => ( 
     
    3834                alias => 'mobirc_httpd', 
    3935            }, 
    40             request_handler => \&App::Mobirc::Web::Handler::handler, 
     36            request_handler => App::Mobirc::Web::Middleware::Encoding->wrap( \&App::Mobirc::Web::Handler::handler ), 
    4137        } 
    4238    )->run; 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Util.pm

    r17804 r17814  
    4242} 
    4343 
    44 # ------------------------------------------------------------------------- 
    45 # FIXME: remove or move to anywhere 
    46  
    47 do { 
    48     use HTTP::Engine::Request; 
    49     my $meta = HTTP::Engine::Request->meta; 
    50     $meta->make_mutable; 
    51     $meta->add_attribute( 
    52         'mobile_agent' => ( 
    53             is => 'ro', 
    54             lazy => 1, 
    55             default => sub { 
    56                 my $self = shift; 
    57                 HTTP::MobileAgent->new($self->headers); 
    58             } 
    59         ) 
    60     ); 
    61     $meta->make_immutable; 
    62 }; 
    63  
    64441; 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Web/Handler.pm

    r17805 r17814  
    1919    my $c = shift; 
    2020 
    21     my $res = _handler($c); 
     21    my $res = _handler($c->req); 
    2222    context->run_hook('response_filter', $res); 
    2323    $c->res($res); # TODO: remove this 
     
    2525 
    2626sub _handler { 
    27     my $c = shift; 
    28     my $req = $c->req; 
     27    my $req = shift; 
    2928 
    3029    context->run_hook('request_filter', $req); 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Web/Middleware/Encoding.pm

    r13031 r17814  
    33use Data::Visitor::Encode; 
    44 
    5 my $dve = Data::Visitor::Encode->new; 
     5sub wrap { 
     6    my ($class, $next) = @_; 
    67 
    7 sub wrap { 
    8     my ($next, $c) = @_; 
     8    sub { 
     9        my $req = shift; 
    910 
    10     my $encoding = $c->req->mobile_agent->encoding; 
    11     for my $method (qw/params query_params body_params/) { 
    12         $c->req->$method( $dve->decode($encoding, $c->req->$method) ); 
    13     } 
     11        my $encoding = $req->mobile_agent->encoding; 
     12        for my $method (qw/params query_params body_params/) { 
     13            $req->$method( Data::Visitor::Encode->decode($encoding, $req->$method) ); 
     14        } 
    1415 
    15     $next->($c); 
     16        $next->($req); 
     17    }; 
    1618} 
    1719 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Web/Middleware/MobileAgent.pm

    r13231 r17814  
    11package App::Mobirc::Web::Middleware::MobileAgent; 
    2 use Moose; 
     2use strict; 
     3use warnings; 
     4use HTTP::Engine::Request; 
    35use HTTP::MobileAgent; 
    46use HTTP::MobileAgent::Plugin::Charset; 
    57 
    6 sub setup { 
     8sub import { 
    79    my $meta = HTTP::Engine::Request->meta; 
    810    $meta->make_mutable; 
  • lang/perl/mobirc/trunk/t/Plugins/Authorizer/BasicAuth.t

    r17793 r17814  
    55use App::Mobirc::Plugin::Authorizer::BasicAuth; 
    66use MIME::Base64 (); 
    7 use HTTP::Engine::Compat::Context; 
     7use t::Utils; 
    88 
    99my $mobirc = App::Mobirc->new( 
     
    1515$mobirc->load_plugin( {module => 'Authorizer::BasicAuth', config => {username => 'dankogai', password => 'kogaidan'}} ); 
    1616 
    17 ok !$mobirc->run_hook_first('authorize', create_req('dankogai', 'dankogai')); 
    18 ok $mobirc->run_hook_first('authorize', create_req('dankogai', 'kogaidan')); 
     17test_he_filter { 
     18    my $req = shift; 
    1919 
    20 sub create_req { 
    21     my ($user, $passwd) = @_; 
    22     my $c = HTTP::Engine::Compat::Context->new; 
    23     $c->req->header('Authorization' => 'Basic ' . MIME::Base64::encode("$user:$passwd", '')); 
    24     $c->req; 
    25 } 
     20    my $set = sub { 
     21        my ($user, $passwd) = @_; 
     22        $req->header('Authorization' => 'Basic ' . MIME::Base64::encode("$user:$passwd", '')); 
     23        $req; 
     24    }; 
     25    ok !$mobirc->run_hook_first('authorize', $set->('dankogai', 'dankogai')); 
     26    ok $mobirc->run_hook_first('authorize', $set->('dankogai', 'kogaidan')); 
     27}; 
    2628 
  • lang/perl/mobirc/trunk/t/Plugins/Authorizer/DoCoMoGUID-authorizer.t

    r17793 r17814  
    33use Test::More; 
    44use App::Mobirc; 
    5 use HTTP::Engine::Compat::Context; 
     5use t::Utils; 
    66 
    77eval "use HTML::StickyQuery::DoCoMoGUID"; 
     
    1717$mobirc->load_plugin( {module => 'Authorizer::DoCoMoGUID', config => {docomo_guid => 'foobar.docomo'}} ); 
    1818 
    19 ok $mobirc->run_hook_first('authorize', create_req('foobar.docomo')), 'login succeeded'; 
    20 ok !$mobirc->run_hook_first('authorize', create_req('invalid_login_id')), 'login failed'; 
     19test_he_filter { 
     20    my $req = shift; 
    2121 
    22 sub create_req { 
    23     my $guid = shift; 
    24     my $c = HTTP::Engine::Compat::Context->new; 
    25     $c->req->header('x-dcmguid' => $guid); 
    26     $c->req; 
    27 } 
     22    $req->header('x-dcmguid' => 'foobar.docomo'); 
     23    ok $mobirc->run_hook_first('authorize', $req), 'login succeeded'; 
    2824 
     25    $req->header('x-dcmguid' => 'invalid_login_id'); 
     26    ok !$mobirc->run_hook_first('authorize', $req), 'login failed'; 
     27}; 
     28 
  • lang/perl/mobirc/trunk/t/Plugins/Authorizer/DoCoMoGUID-html_filter.t

    r17804 r17814  
    44use App::Mobirc; 
    55use HTTP::MobileAgent; 
    6 use HTTP::Engine::Compat middlewares => [ 
    7     qw/ +App::Mobirc::Web::Middleware::MobileAgent / 
    8 ]; 
     6use t::Utils; 
    97 
    108eval "use HTML::StickyQuery::DoCoMoGUID"; 
     
    2220my $html = '<a href="/">foo</a>'; 
    2321 
    24 my ($c, $got) = $mobirc->run_hook_filter('html_filter', create_req(), $html); 
     22test_he_filter { 
     23    my $req = shift; 
     24    $req->user_agent('DoCoMo/2.0 SH904i(c100;TB;W24H16)'); 
     25    ($req, $html) = $mobirc->run_hook_filter('html_filter', $req, $html); 
     26}; 
    2527 
    26 is $got, '<a href="/?guid=ON">foo</a>'; 
     28is $html, '<a href="/?guid=ON">foo</a>'; 
    2729 
    28 sub create_req { 
    29     my $req = HTTP::Engine::Compat::Context->new->req; 
    30     $req->user_agent('DoCoMo/2.0 SH904i(c100;TB;W24H16)'); 
    31     $req; 
    32 } 
  • lang/perl/mobirc/trunk/t/Plugins/GPS.t

    r17799 r17814  
    33use App::Mobirc; 
    44use Test::More; 
    5 use HTTP::Engine::Compat::Context; 
    6 use HTTP::Engine::Compat middlewares => [ 
    7     '+App::Mobirc::Web::Middleware::MobileAgent' 
    8 ]; 
     5use t::Utils; 
    96 
    107eval q{ use HTTP::MobileAgent::Plugin::Locator }; 
     
    2017$mobirc->load_plugin({module => 'GPS', config => {}}); 
    2118 
    22 my $req = sub { 
    23     my $req = HTTP::Engine::Compat::Context->new()->req(); 
     19test_he_filter { 
     20    my $req = shift; 
    2421    $req->user_agent('DoCoMo/2.0 SH904i(c100;TB;W24H16)'); 
    2522    $req->query_params( 
    2623        { lat => '35.21.03.342', lon => '138.34.45.725', geo => 'wgs84' } ); 
    2724    $req->path('/channel/%23coderepos/gps_do'); 
    28     $req; 
    29 }->(); 
    3025 
    31 my $res = $mobirc->run_hook_first('httpd', $req); 
    32 ok $res; 
    33 is $res->status, 302; 
    34 is $res->header('Location'), '/channels/%23coderepos?msg=L:Lat%3A%2035.21.03.342%2C%20Lng%3A%20138.34.45.725'; 
     26    my $res = $mobirc->run_hook_first('httpd', $req); 
     27    ok $res; 
     28    is $res->status, 302; 
     29    is $res->header('Location'), '/channels/%23coderepos?msg=L:Lat%3A%2035.21.03.342%2C%20Lng%3A%20138.34.45.725'; 
     30}; 
    3531 
  • lang/perl/mobirc/trunk/t/Utils.pm

    r17805 r17814  
    55our @EXPORT = qw/test_he test_he_filter/; 
    66use HTTP::Engine; 
     7use App::Mobirc::Web::Middleware::MobileAgent; 
    78 
    89sub test_he {