Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 8c773ad0ec490aaea0bbb6ab284675f0743655e4 1 parent 0acb9ac
@kentaro authored
View
12 lib/Ridge/Lite.pm
@@ -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
20 lib/Ridge/Lite/Action.pm
@@ -5,12 +5,13 @@ 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)) {
@@ -18,11 +19,20 @@ sub install {
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
2  lib/Ridge/Lite/Config.pm
@@ -4,4 +4,6 @@ use warnings;
use base qw(Ridge::Config);
+sub find_root { shift->param('root') }
+
!!1;
View
4 lib/Ridge/Lite/Request.pm
@@ -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
7 lib/Ridge/Lite/URI.pm
@@ -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},
+ );
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.