Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Action attribute

  • Loading branch information...
commit d839022230fadd94a77985d635fe234771133446 1 parent 29d4b6b
Zbigniew Lukasiak authored
Showing with 16 additions and 10 deletions.
  1. +13 −6 lib/WebNano/Controller.pm
  2. +3 −4 lib/WebNano/DirController.pm
View
19 lib/WebNano/Controller.pm
@@ -6,10 +6,11 @@ package WebNano::Controller;
use URI::Escape 'uri_unescape';
use Plack::Request;
-use Object::Tiny::RW qw/ app env self_url url_map _req /;
+use Object::Tiny::RW qw/ app env self_url url_map _req path/;
sub DEBUG { shift->app->DEBUG }
+
sub req {
my $self = shift;
return $self->_req if defined $self->_req;
@@ -25,9 +26,16 @@ sub render {
return $self->app->renderer->render( c => $self, @_ );
}
+sub action { shift->path->[0]; }
+sub action_args {
+ my $self = shift;
+ my @path = @{ $self->path };
+ return @path[ 1 .. $#path ];
+}
+
sub local_dispatch {
- my ( $self, @parts ) = @_;
- my $name = uri_unescape( shift @parts );
+ my ( $self ) = @_;
+ my $name = $self->action;
$name = 'index' if !defined( $name ) || !length( $name );
my $action;
if( my $map = $self->url_map ){
@@ -42,7 +50,7 @@ sub local_dispatch {
$action = $self->can( $method ) if !$action;
my $out;
if( $action ){
- $out = $action->( $self, @parts );
+ $out = $action->( $self, @{ $self->action_args } );
}
warn 'No local action found in "' . ref($self) . qq{" for "$name"\n} if !defined( $out ) && $self->DEBUG;
return $out;
@@ -50,9 +58,8 @@ sub local_dispatch {
sub handle {
my ( $class, %args ) = @_;
- my $path = delete $args{path};
my $self = $class->new( %args );
- return $self->local_dispatch( @$path );
+ return $self->local_dispatch();
};
1;
View
7 lib/WebNano/DirController.pm
@@ -15,11 +15,10 @@ sub _self_path{
sub handle {
my ( $class, %args ) = @_;
- my $path = delete $args{path};
my $self = $class->new( %args );
- my $out = $self->local_dispatch( @$path );
+ my $out = $self->local_dispatch();
return $out if defined( $out );
- my $path_part = shift @$path;
+ my $path_part = $self->action;
$path_part =~ s/::|'//g if defined( $path_part );
return if !length( $path_part );
my $controller_class = find_nested( $class->_self_path . $path_part, $args{app}->controller_search_path );
@@ -30,7 +29,7 @@ sub handle {
warn qq{Dispatching to "$controller_class"\n} if $self->DEBUG;
return $controller_class->handle(
%args,
- path => $path,
+ path => $self->action_args,
self_url => $args{self_url} . $path_part . '/',
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.