Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CRUD Fixes, utf8 encoding of output

  • Loading branch information...
commit 190387f4a50a3ff626d7d6c4cacc3efeb9dee956 1 parent 8c3f88e
Zbigniew Lukasiak authored
View
16 extensions/WebNano-Controller-CRUD/lib/WebNano/Controller/CRUD.pm
@@ -22,9 +22,9 @@ has class_actions => (
);
around 'local_dispatch' => sub {
- my( $orig, $self, $path) = @_;
- my( $path_part, $method, @args ) = split qr{/}, $path;
+ my( $orig, $self, $path_part, $method, @args ) = @_;
$method ||= 'view';
+ warn "$path_part, $method, @args";
if( $path_part && $path_part =~ /^\d+$/ && $self->record_actions->{ $method } ){
my $id = $path_part;
my $rs = $self->application->schema->resultset( 'Dvd' );
@@ -40,14 +40,14 @@ around 'local_dispatch' => sub {
if( defined $path_part && $self->class_actions->{$path_part} ){
return $self->$path_part( $method, @args );
}
- return $self->$orig( $path );
+ return $self->$orig( $path_part, $method, @args );
};
sub list {
my( $self ) = @_;
my $rs = $self->application->schema->resultset( $self->rs_name );
- return $self->render( 'list.tt', { items => [ $rs->search ] } );
+ return $self->render( template => 'list.tt', items => [ $rs->search ] );
}
sub create {
@@ -67,19 +67,19 @@ sub create {
return $res;
}
$form->field( 'submit' )->value( 'Create' );
- return $self->render( 'edit.tt', { form => $form->render } );
+ return $self->render( template => 'edit.tt', form => $form->render );
}
sub view {
my ( $self, $record ) = @_;
- return $self->render( 'record.tt', { record => $record } );
+ return $self->render( template => 'record.tt', record => $record );
}
sub delete {
my ( $self, $record ) = @_;
if( $self->request->method eq 'GET' ){
- return $self->render( 'delete.tt', { record => $record } );
+ return $self->render( template => 'delete.tt', record => $record );
}
else{
$record->delete;
@@ -104,7 +104,7 @@ sub edit {
return $res;
}
$form->field( 'submit' )->value( 'Update' );
- return $self->render( 'edit.tt', { form => $form->render } );
+ return $self->render( template => 'edit.tt', form => $form->render );
}
1;
View
6 extensions/WebNano-Controller-CRUD/t/data/templates/DvdWithBaseCRUD/list.tt
@@ -16,9 +16,9 @@
<td>
[% record.creation_date %]
</td>
-<td><a href="[% self_url %]record/[% record.id %]/view">View</a></td>
-<td><a href="[% self_url %]record/[% record.id %]/edit">Edit</a></td>
-<td><a href="[% self_url %]record/[% record.id %]/delete">Delete</a></td>
+<td><a href="[% c.self_url %][% record.id %]/view">View</a></td>
+<td><a href="[% c.self_url %][% record.id %]/edit">Edit</a></td>
+<td><a href="[% c.self_url %][% record.id %]/delete">Delete</a></td>
</tr>
[% END %]
</body>
View
21 extensions/WebNano-Controller-CRUD/t/lib/MyApp/Controller.pm
@@ -4,29 +4,14 @@ use Moose;
use MooseX::NonMoose;
extends 'WebNano::Controller';
-has 'url_map' => ( is => 'ro', default => sub { { 'mapped url' => 'mapped_url' } } );
-
sub index_action {
my $self = shift;
- return $self->render( 'index.tt' );
+ my $res = $self->request->new_response();
+ $res->redirect( '/DvdWithBaseCRUD' );
+ return $res;
}
-sub mapped_url { 'This is the mapped url page' }
-
-sub streaming_action {
- my $self = shift;
- return sub {
- my $respond = shift;
- my $writer = $respond->([
- 200,
- [ 'Content-Type' => 'text/plain', ],
- ]);
- $writer->write( "Hello, " );
- $writer->write( $self->request->param( 'who' ) );
- $writer->close();
- }
-}
1;
View
BIN  extensions/WebNano-Controller-CRUD/t/tmp/dvdzbr.db
Binary file not shown
View
3  lib/WebNano.pm
@@ -10,6 +10,7 @@ use Plack::Response;
use Scalar::Util qw(blessed);
use Object::Tiny::RW 'renderer';
use Try::Tiny;
+use Encode;
sub psgi_callback {
my $self = shift;
@@ -48,7 +49,7 @@ sub handle {
else{
my $res = Plack::Response->new(200);
$res->content_type('text/html');
- $res->body( $out );
+ $res->body( encode( 'utf8', $out ) );
return $res->finalize;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.