Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

action_postfix method

  • Loading branch information...
commit 360181eef3bfbfd4345ceeafb249acfcfd5872c2 1 parent ae8ec9e
Zbigniew Lukasiak authored
View
2  examples/DvdDatabase/lib/DvdDatabase/Controller/Dvd.pm
@@ -45,7 +45,7 @@ sub record_action {
path => [ $action ],
app => $self->app,
env => $self->env,
- self_url => $self->self_url . "record/$id/",
+ self_url => $self->self_url . "record/$id",
record => $record,
);
}
View
2  examples/DvdDatabase/lib/DvdDatabase/Controller/Dvd1.pm
@@ -93,7 +93,7 @@ sub edit_action {
);
if( $req->method eq 'POST' && $form->process() ){
my $res = $req->new_response();
- $res->redirect( $self->self_url . '/' . $record->id . '/view' );
+ $res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
return $res;
}
$form->field( 'submit' )->value( 'Update' );
View
2  examples/DvdDatabase/lib/DvdDatabase/Controller/Dvd2.pm
@@ -82,7 +82,7 @@ sub edit_action {
);
if( $req->method eq 'POST' && $form->process() ){
my $res = $req->new_response();
- $res->redirect( $self->self_url . '/' . $record->id . '/view' );
+ $res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
return $res;
}
$form->field( 'submit' )->value( 'Update' );
View
39 examples/DvdDatabase/lib/DvdDatabase/Controller/DvdSimpleUrl.pm
@@ -6,12 +6,6 @@ extends 'WebNano::Controller';
use DvdDatabase::Controller::Dvd::Form;
-has url_map => (
- is => 'ro',
- isa => 'HashRef',
- default => sub { { view => 'view', 'delete' => 'delete', edit => 'edit' } }
-);
-
has record => (
is => 'ro',
lazy => 1,
@@ -26,20 +20,32 @@ sub _build_record {
return;
}
+sub record_path {
+ my $self = shift;
+ return defined( $self->path->[0] ) and $self->path->[0] =~ /^\d+$/;
+}
+
+sub action_postfix {
+ my $self = shift;
+ if( $self->record_path ){
+ return '_record';
+ }
+ else{
+ return '_action';
+ }
+}
+
sub action_name {
my $self = shift;
- my @path = @{ $self->path };
- warn "@path";
- if( defined( $path[0] ) and $path[0] =~ /^\d+$/ ){
+ if( $self->record_path ){
if( defined $self->record ){
- warn $self->record;
- return $path[1];
+ return $self->path->[1];
}
else{
- return 'no_record';
+ return 'no';
}
}
- return $path[0];
+ return $self->path->[0] || 'index';
}
sub index_action {
@@ -66,13 +72,12 @@ sub create_action {
return $self->render( template => 'edit.tt', form => $form->render );
}
-sub view {
+sub view_record {
my ( $self, ) = @_;
-
return $self->render( record => $self->record );
}
-sub delete {
+sub delete_record {
my ( $self, ) = @_;
if( $self->req->method eq 'GET' ){
return $self->render( record => $self->record );
@@ -85,7 +90,7 @@ sub delete {
}
}
-sub edit {
+sub edit_record {
my ( $self, ) = @_;
my $req = $self->req;
my $form = DvdDatabase::Controller::Dvd::Form->new(
View
8 lib/WebNano/Controller.pm
@@ -25,7 +25,7 @@ sub render {
return $self->app->renderer->render( c => $self, @_ );
}
-sub action_name { shift->path->[0] }
+sub action_name { shift->path->[0] // 'index' }
sub action_args {
my $self = shift;
@@ -33,12 +33,12 @@ sub action_args {
return @path[ 1 .. $#path ];
}
+sub action_postfix { '_action' };
+
sub local_dispatch {
my ( $self ) = @_;
my $action;
my $name = uri_unescape( $self->action_name );
- $name = 'index' if !defined( $name ) || !length( $name );
- warn "dispatching for $name";
if( my $map = $self->url_map ){
if( ref $map eq 'HASH' ){
$action = $self->can( $map->{$name} ) if $map->{$name};
@@ -48,7 +48,7 @@ sub local_dispatch {
}
}
if( !$action ){
- $action = $self->can( $name . '_action' ) if defined $name;
+ $action = $self->can( $name . $self->action_postfix ) if defined $name;
}
my $out;
if( $action ){
View
8 lib/WebNano/Renderer/TTiny.pm
@@ -22,23 +22,21 @@ sub _to_list {
sub render {
my( $self, %vars ) = @_;
my $c = $vars{c};
-
my @search_path;
+ my $action;
if( $c ){
my $path = ref $c;
$path =~ s/.*::Controller(::)?//;
$path =~ s{::}{/};
@search_path = ( $path, @{ $c->template_search_path });
+ $action = $c->action_name;
}
if( !@search_path ){
@search_path = ( '' );
}
my $template = $vars{template};
if( !$template ){
- my @caller = caller(2);
- $template = $caller[3];
- $template =~ s/_action$//;
- $template =~ s/^.*:://;
+ $template = $action;
$template .= '.' . $self->TEMPLATE_EXTENSION if $self->TEMPLATE_EXTENSION;
}
my $full_template;
Please sign in to comment.
Something went wrong with that request. Please try again.