Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added the Book controller

  • Loading branch information...
commit 7528af68e7711aa54247c6838d51acecc71482fc 1 parent 5477539
Phillip Smith authored August 15, 2011
68  lib/Catalyst/Default/Controller/Books.pm
... ...
@@ -0,0 +1,68 @@
  1
+package Catalyst::Default::Controller::Books;
  2
+use Moose;
  3
+use namespace::autoclean;
  4
+
  5
+BEGIN {extends 'Catalyst::Controller'; }
  6
+
  7
+=head1 NAME
  8
+
  9
+Catalyst::Default::Controller::Books - Catalyst Controller
  10
+
  11
+=head1 DESCRIPTION
  12
+
  13
+Catalyst Controller.
  14
+
  15
+=head1 METHODS
  16
+
  17
+=cut
  18
+
  19
+
  20
+=head2 index
  21
+
  22
+=cut
  23
+
  24
+sub index :Path :Args(0) {
  25
+    my ( $self, $c ) = @_;
  26
+
  27
+    $c->response->body('Matched Catalyst::Default::Controller::Books in Books.');
  28
+}
  29
+
  30
+=head2 list
  31
+
  32
+Fetch all book objects and pass to books/list.tt2 in stash to be displayed
  33
+
  34
+=cut
  35
+
  36
+sub list :Local {
  37
+    # Retrieve the usual Perl OO '$self' for this object. $c is the Catalyst
  38
+    # 'Context' that's used to 'glue together' the various components
  39
+    # that make up the application
  40
+    my ($self, $c) = @_;
  41
+
  42
+    # Retrieve all of the book records as book model objects and store in the
  43
+    # stash where they can be accessed by the TT template
  44
+    # $c->stash(books => [$c->model('DB::Book')->all]);
  45
+    # But, for now, use this code until we create the model later
  46
+    $c->stash(books => '');
  47
+
  48
+    # Set the TT template to use.  You will almost always want to do this
  49
+    # in your action methods (action methods respond to user input in
  50
+    # your controllers).
  51
+    $c->stash(template => 'books/list.tt2');
  52
+}
  53
+
  54
+
  55
+=head1 AUTHOR
  56
+
  57
+Phillip Smith
  58
+
  59
+=head1 LICENSE
  60
+
  61
+This library is free software. You can redistribute it and/or modify
  62
+it under the same terms as Perl itself.
  63
+
  64
+=cut
  65
+
  66
+__PACKAGE__->meta->make_immutable;
  67
+
  68
+1;
10  t/controller_Books.t
... ...
@@ -0,0 +1,10 @@
  1
+use strict;
  2
+use warnings;
  3
+use Test::More;
  4
+
  5
+
  6
+use Catalyst::Test 'Catalyst::Default';
  7
+use Catalyst::Default::Controller::Books;
  8
+
  9
+ok( request('/books')->is_success, 'Request should succeed' );
  10
+done_testing();

0 notes on commit 7528af6

Please sign in to comment.
Something went wrong with that request. Please try again.