Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (46 sloc) 1.507 kb
5d1a299 Some more demoosifying
Zbigniew Lukasiak authored
1 use strict;
2 use warnings;
8b2c409 special dispatch on ids
Zbigniew Lukasiak authored
3
29782b7 extensions and examples as separate dists
Zbigniew Lukasiak authored
4 package DvdDatabase::Controller::Dvd;
5d1a299 Some more demoosifying
Zbigniew Lukasiak authored
5 use base 'WebNano::Controller';
8b2c409 special dispatch on ids
Zbigniew Lukasiak authored
6
29782b7 extensions and examples as separate dists
Zbigniew Lukasiak authored
7 use DvdDatabase::Controller::Dvd::Form;
8 use DvdDatabase::Controller::Dvd::Record;
c24e4d1 url_map (thanks Matt Lawrence for the idea)
zby authored
9
4e803ed back to find_action
Zbigniew Lukasiak authored
10 sub index_action {
8b2c409 special dispatch on ids
Zbigniew Lukasiak authored
11 my( $self ) = @_;
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
12 my $rs = $self->app->schema->resultset( 'Dvd' );
95ab491 finding template based on caller
Zbigniew Lukasiak authored
13 return $self->render( template => 'list.tt', items => [ $rs->search ] );
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
14 }
15
4e803ed back to find_action
Zbigniew Lukasiak authored
16 sub create_action {
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
17 my ( $self ) = @_;
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
18 my $req = $self->req;
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
19
29782b7 extensions and examples as separate dists
Zbigniew Lukasiak authored
20 my $form = DvdDatabase::Controller::Dvd::Form->new(
f681961 Hash::Multivalue is not compatible with FormHandler (for params)
Zbigniew Lukasiak authored
21 params => $req->parameters->as_hashref,
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
22 schema => $self->app->schema,
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
23 );
24 if( $req->method eq 'POST' && $form->process() ){
25 my $record = $form->item;
26 my $res = $req->new_response();
27 $res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
28 return $res;
29 }
30 $form->field( 'submit' )->value( 'Create' );
95ab491 finding template based on caller
Zbigniew Lukasiak authored
31 return $self->render( template => 'edit.tt', form => $form->render );
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
32 }
33
4e803ed back to find_action
Zbigniew Lukasiak authored
34 sub record_action {
16fe51d first commit
Zbigniew Lukasiak authored
35 my( $self, $id, $action ) = @_;
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
36 my $rs = $self->app->schema->resultset( 'Dvd' );
16fe51d first commit
Zbigniew Lukasiak authored
37 my $record = $rs->find( $id );
38 if( ! $record ) {
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
39 my $res = $self->req->new_response(404);
16fe51d first commit
Zbigniew Lukasiak authored
40 $res->content_type('text/plain');
41 $res->body( 'No record with id: ' . $id );
42 return $res;
43 }
29782b7 extensions and examples as separate dists
Zbigniew Lukasiak authored
44 return DvdDatabase::Controller::Dvd::Record->handle(
3eb6ff2 parsing path at the first step
Zbigniew Lukasiak authored
45 path => [ $action ],
20f3e7c application -> app, request -> req
Zbigniew Lukasiak authored
46 app => $self->app,
30dac45 Using PSGI environment instead of Plack::Request
Zbigniew Lukasiak authored
47 env => $self->env,
fe5131a Using MooseX::MethodAttributes
Zbigniew Lukasiak authored
48 self_url => $self->self_url . "record/$id/",
49 record => $record,
50 );
16fe51d first commit
Zbigniew Lukasiak authored
51 }
52
53
54
55 1;
Something went wrong with that request. Please try again.