Permalink
Browse files

EncodeingのPlugin指定がない場合はKamui::Plugin::Encodeをデフォルトとする

  • Loading branch information...
1 parent 27f8c91 commit 7946c678e680b417ccff45c885bf768a9d22ee05 @nekokak committed Nov 17, 2009
Showing with 38 additions and 1 deletion.
  1. +2 −1 eg/lib/MyAPP/Web/Handler.pm
  2. +5 −0 lib/Kamui/Web/Context.pm
  3. +31 −0 t/020_web/context/default_encoding.t
@@ -2,7 +2,8 @@ package MyAPP::Web::Handler;
use Kamui::Web::Handler;
use_container 'MyAPP::Container';
-use_plugins [qw/+MyAPP::Plugin::Foo Mobile::Attribute Encode/];
+#use_plugins [qw/+MyAPP::Plugin::Foo Mobile::Attribute Encode/];
+use_plugins [qw/+MyAPP::Plugin::Foo Mobile::Attribute/];
#use_plugins [qw/+MyAPP::Plugin::Foo Mobile::Attribute Mobile::Encode/];
use_context 'MyAPP::Web::Context';
use_view 'Kamui::View::TT';
@@ -14,6 +14,7 @@ my @initialize_plugins;
my @finalize_plugins;
sub load_plugins {
my ($class, $plugins) = @_;
+ $class = ref $class || $class;
for my $plugin (@{$plugins}) {
my $pkg = _plugin_name($plugin);
@@ -168,6 +169,10 @@ sub is_detach {
sub initialize {
my $self = shift;
+ unless ( $self->can('prepare_encoding') ) {
+ $self->load_plugins([qw/Encode/]);
+ }
+
$self->prepare_encoding();
$self->initialize_plugins;
}
@@ -0,0 +1,31 @@
+use t::Utils;
+use Test::Declare;
+use Kamui::Web::Context;
+use Mock::Container;
+use Mock::Web::Handler;
+use Mock::Web::Dispatcher;
+
+plan tests => blocks;
+
+describe 'default encoding tests' => run {
+ test 'set default encoding module' => run {
+ my $env = +{
+ HTTP_HOST => 'example.com',
+ REQUEST_METHOD => 'GET',
+ SCRIPT_NAME => '/',
+ PATH_INFO => '/',
+ QUERY_STRING => 'p=query',
+ };
+
+ my $c = Kamui::Web::Context->new(
+ env => $env,
+ dispatch_rule => Mock::Web::Dispatcher->determine($env),
+ conf => container('conf'),
+ app => 'Mock::Web::Handler',
+ );
+ ok not $c->can('prepare_encoding');
+ $c->initialize;
+ can_ok $c, 'prepare_encoding';
+ };
+};
+

0 comments on commit 7946c67

Please sign in to comment.