Permalink
Browse files

メソッドによる振り分けをちゃんとする

  • Loading branch information...
kentaro committed Apr 2, 2011
1 parent 0acb9ac commit 8c773ad0ec490aaea0bbb6ab284675f0743655e4
Showing with 31 additions and 14 deletions.
  1. +6 −6 lib/Ridge/Lite.pm
  2. +15 −5 lib/Ridge/Lite/Action.pm
  3. +2 −0 lib/Ridge/Lite/Config.pm
  4. +2 −2 lib/Ridge/Lite/Request.pm
  5. +6 −1 lib/Ridge/Lite/URI.pm
View
@@ -38,15 +38,15 @@ sub process {
sub install_config {
my $class = shift;
my $config_class = join '::', $class, 'Config';
- eval <<"EOS";
+
+ if (!$config_class->use) {
+ eval <<"EOS";
package $config_class;
use base qw(Ridge::Lite::Config);
-
-package Ridge::Config;
-no warnings 'redefine';
-sub find_root { shift->param('root') }
EOS
- $class->config($config_class->new);
+ }
+
+ $class->config($config_class->new->setup);
}
sub make_request {
View
@@ -5,24 +5,34 @@ use warnings;
use Ridge::Lite::Engine;
sub install {
- my ($class, $action, $view, $code) = @_;
+ my ($class, $action, $method, $view, $code) = @_;
+ my $method_action = join '_', '', $action, lc $method;
- if (!$class->can($action)) {
+ if (!$class->can($method_action)) {
no strict 'refs';
no warnings 'redefine';
- *{"$class\::$action"} = ($code || sub {});
+ *{"$class\::$method_action"} = ($code || sub {});
}
if (!Ridge::Lite::Engine->can($action)) {
eval <<"EOS";
package Ridge::Lite::Engine;
sub $action : Public {
my (\$self, \$r) = \@_;
- @{[$view && '\$r->view->available(q{$view});']}
- Ridge::Lite::Action::${action}(\$r);
+ \$r->follow_method;
}
EOS
}
+
+ eval <<"EOS";
+package Ridge::Lite::Engine;
+no warnings 'redefine';
+sub $method_action {
+ my (\$self, \$r) = \@_;
+ @{[$view && "\$r->view->available(q{$view});"]}
+ Ridge::Lite::Action::$method_action(\$r);
+}
+EOS
}
!!1;
View
@@ -4,4 +4,6 @@ use warnings;
use base qw(Ridge::Config);
+sub find_root { shift->param('root') }
+
!!1;
@@ -7,8 +7,8 @@ use base qw(Ridge::Request);
$Ridge::Request::PREFERRED_URI = 'Ridge::Lite::URI';
sub route {
- my ($self, $namespace, $router) = @_;
- $self->uri->route($namespace, $router, $self->env);
+ my ($self, $router) = @_;
+ $self->uri->route($router, $self->env);
}
!!1;
View
@@ -25,7 +25,12 @@ sub route {
$self->param(%params) if %params;
if ($route->{code}) {
- Ridge::Lite::Action->install($self->action, $self->view || '', $route->{code});
+ Ridge::Lite::Action->install(
+ $self->action,
+ $env->{REQUEST_METHOD},
+ $self->view || '',
+ $route->{code},
+ );
}
}
}

0 comments on commit 8c773ad

Please sign in to comment.