Skip to content
Browse files

local_dispatch called with parsed path

  • Loading branch information...
1 parent 12f770b commit f8550f30d518a492852523e4204d89d64d1e5939 Zbigniew Lukasiak committed
View
10 examples/DvdDatabase/lib/DvdDatabase/Controller/Dvd2.pm
@@ -7,9 +7,8 @@ extends 'WebNano::Controller';
use DvdDatabase::Controller::Dvd::Form;
around 'local_dispatch' => sub {
- my( $orig, $self, $path, @args ) = @_;
- if( $path =~ s{^record/(\d+)/}{} ){
- my $id = $1;
+ my( $orig, $self, $path, $id, $method, @args ) = @_;
+ if( defined $path && $path eq 'record' ){
my $rs = $self->app->schema->resultset( 'Dvd' );
my $record = $rs->find( $id );
if( ! $record ) {
@@ -19,14 +18,15 @@ around 'local_dispatch' => sub {
return $res;
}
unshift @args, $record;
+ return $self->$orig( $method, @args );
}
- if( $path =~ m{^(view|edit|delete)/} ){
+ if( defined $path && $path =~ m{^(view|edit|delete)} ){
my $res = $self->req->new_response(404);
$res->content_type('text/plain');
$res->body( 'No page found' );
return $res;
}
- return $self->$orig( $path, @args );
+ return $self->$orig( $path, $id, $method, @args );
};
sub index_action {
View
5 examples/DvdDatabase/lib/DvdDatabase/Controller/DvdSimpleUrl.pm
@@ -13,8 +13,7 @@ has record_methods => (
);
around 'local_dispatch' => sub {
- my( $orig, $self, $path) = @_;
- my( $id, $method, @args ) = split qr{/}, $path;
+ my( $orig, $self, $id, $method, @args ) = @_;
$method ||= 'view';
if( $id && $id =~ /^\d+$/ && $self->record_methods->{ $method } ){
my $rs = $self->app->schema->resultset( 'Dvd' );
@@ -27,7 +26,7 @@ around 'local_dispatch' => sub {
}
return $self->$method( $record, @args );
}
- return $self->$orig( $path );
+ return $self->$orig( $id, $method, @args );
};
sub index_action {
View
8 lib/WebNano/Controller.pm
@@ -26,8 +26,7 @@ sub render {
}
sub local_dispatch {
- my ( $self, $path, @args ) = @_;
- my @parts = split /\//, $path;
+ my ( $self, @parts ) = @_;
my $name = uri_unescape( shift @parts );
$name = 'index' if !defined( $name ) || !length( $name );
my $action;
@@ -43,7 +42,7 @@ sub local_dispatch {
$action = $self->can( $method ) if !$action;
my $out;
if( $action ){
- $out = $action->( $self, @args, @parts );
+ $out = $action->( $self, @parts );
}
warn 'No local action found in "' . ref($self) . qq{" for "$name"\n} if !defined( $out ) && $self->DEBUG;
return $out;
@@ -53,7 +52,8 @@ sub handle {
my ( $class, %args ) = @_;
my $path = delete $args{path};
my $self = $class->new( %args );
- return $self->local_dispatch( $path );
+ my @parts = split /\//, $path;
+ return $self->local_dispatch( @parts );
};
1;
View
3 lib/WebNano/DirController.pm
@@ -17,7 +17,8 @@ sub handle {
my ( $class, %args ) = @_;
my $path = delete $args{path};
my $self = $class->new( %args );
- my $out = $self->local_dispatch( $path );
+ my @parts = split /\//, $path;
+ my $out = $self->local_dispatch( @parts );
return $out if defined($out);
my( $path_part, $new_path ) = ( $path =~ qr{^([^/]*)/?(.*)} );
$path_part =~ s/::|'//g if defined( $path_part );

0 comments on commit f8550f3

Please sign in to comment.
Something went wrong with that request. Please try again.