Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (52 sloc) 1.727 kb
bb98c871 »
2012-03-08 Two class example for simple url
1 use strict;
2 use warnings;
3
4 package DvdDatabase::Controller::DvdSimpleUrl_TwoClasses;
5 use Moose;
6 use MooseX::NonMoose;
7
8 extends 'WebNano::Controller';
9
10 use DvdDatabase::Controller::Dvd::Form;
11 use DvdDatabase::Controller::Dvd::Record;
12
13
14 around 'local_dispatch' => sub {
85a9c83a »
2012-05-03 Getting rid of DirController; path attribute for controllers
15 my( $orig, $self ) = @_;
16 my( $id, @args ) = @{ $self->path };
bb98c871 »
2012-03-08 Two class example for simple url
17 if( $id && $id =~ /^\d+$/ ){
18 my $rs = $self->app->schema->resultset( 'Dvd' );
19 my $record = $rs->find( $id );
20 if( ! $record ) {
21 my $res = $self->req->new_response(404);
22 $res->content_type('text/plain');
23 $res->body( 'No record with id: ' . $id );
24 return $res;
25 }
26 return DvdDatabase::Controller::Dvd::Record->handle(
27 path => [ @args ],
28 app => $self->app,
29 env => $self->env,
30 self_url => $self->self_url . "$id/",
31 record => $record,
32 );
33 }
85a9c83a »
2012-05-03 Getting rid of DirController; path attribute for controllers
34 return $self->$orig();
bb98c871 »
2012-03-08 Two class example for simple url
35 };
36
37
38 sub index_action {
39 my( $self ) = @_;
40 my $rs = $self->app->schema->resultset( 'Dvd' );
41 return $self->render( template => 'list.tt', items => [ $rs->search ] );
42 }
43
44 sub create_action {
45 my ( $self ) = @_;
46 my $req = $self->req;
47
48 my $form = DvdDatabase::Controller::Dvd::Form->new(
49 params => $req->parameters->as_hashref,
50 schema => $self->app->schema,
51 );
52 if( $req->method eq 'POST' && $form->process() ){
53 my $record = $form->item;
54 my $res = $req->new_response();
55 $res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
56 return $res;
57 }
58 $form->field( 'submit' )->value( 'Create' );
59 return $self->render( template => 'edit.tt', form => $form->render );
60 }
61
62
63
64 1;
Something went wrong with that request. Please try again.