Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Two class example for simple url

  • Loading branch information...
commit bb98c8718787068b55d3c084aaa4531ecfd29aca 1 parent 29d4b6b
Zbigniew Lukasiak authored
View
63 examples/DvdDatabase/lib/DvdDatabase/Controller/DvdSimpleUrl_TwoClasses.pm
@@ -0,0 +1,63 @@
+use strict;
+use warnings;
+
+package DvdDatabase::Controller::DvdSimpleUrl_TwoClasses;
+use Moose;
+use MooseX::NonMoose;
+
+extends 'WebNano::Controller';
+
+use DvdDatabase::Controller::Dvd::Form;
+use DvdDatabase::Controller::Dvd::Record;
+
+
+around 'local_dispatch' => sub {
+ my( $orig, $self, $id, @args ) = @_;
+ if( $id && $id =~ /^\d+$/ ){
+ my $rs = $self->app->schema->resultset( 'Dvd' );
+ my $record = $rs->find( $id );
+ if( ! $record ) {
+ my $res = $self->req->new_response(404);
+ $res->content_type('text/plain');
+ $res->body( 'No record with id: ' . $id );
+ return $res;
+ }
+ return DvdDatabase::Controller::Dvd::Record->handle(
+ path => [ @args ],
+ app => $self->app,
+ env => $self->env,
+ self_url => $self->self_url . "$id/",
+ record => $record,
+ );
+ }
+ return $self->$orig( $id, @args );
+};
+
+
+sub index_action {
+ my( $self ) = @_;
+ my $rs = $self->app->schema->resultset( 'Dvd' );
+ return $self->render( template => 'list.tt', items => [ $rs->search ] );
+}
+
+sub create_action {
+ my ( $self ) = @_;
+ my $req = $self->req;
+
+ my $form = DvdDatabase::Controller::Dvd::Form->new(
+ params => $req->parameters->as_hashref,
+ schema => $self->app->schema,
+ );
+ if( $req->method eq 'POST' && $form->process() ){
+ my $record = $form->item;
+ my $res = $req->new_response();
+ $res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
+ return $res;
+ }
+ $form->field( 'submit' )->value( 'Create' );
+ return $self->render( template => 'edit.tt', form => $form->render );
+}
+
+
+
+1;
View
2  examples/DvdDatabase/t/simple_url.t
@@ -9,7 +9,7 @@ use File::Copy;
use Plack::Middleware::Session;
use Test::WWW::Mechanize::PSGI;
-for my $controller( qw/DvdSimpleUrl/ ){
+for my $controller( qw/DvdSimpleUrl DvdSimpleUrl_TwoClasses/ ){
copy('t/data/dvdzbr.db','dvdzbr.db') or die "Copy failed: $!";
my $app = Plack::Middleware::Session->wrap( DvdDatabase->new()->psgi_app );
View
6 examples/DvdDatabase/templates/DvdSimpleUrl_TwoClasses/edit.tt
@@ -0,0 +1,6 @@
+<html>
+<body>
+[% form %]
+</body>
+</html>
+
View
26 examples/DvdDatabase/templates/DvdSimpleUrl_TwoClasses/list.tt
@@ -0,0 +1,26 @@
+<html>
+<body>
+<table>
+<tr>
+<th>name</td>
+<th>creation_date</td>
+<td></td>
+<td></td>
+<td></td>
+</tr>
+[% FOREACH record IN items %]
+<tr>
+<td>
+[% record.name %]
+</td>
+<td>
+[% record.creation_date %]
+</td>
+<td><a href="[% self_url %][% record.id %]/view">View</a></td>
+<td><a href="[% self_url %][% record.id %]/edit">Edit</a></td>
+<td><a href="[% self_url %][% record.id %]/delete">Delete</a></td>
+</tr>
+[% END %]
+</body>
+</html>
+
Please sign in to comment.
Something went wrong with that request. Please try again.