Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the Book controller

  • Loading branch information...
commit 7528af68e7711aa54247c6838d51acecc71482fc 1 parent 5477539
@phillipadsmith authored
Showing with 78 additions and 0 deletions.
  1. +68 −0 lib/Catalyst/Default/Controller/Books.pm
  2. +10 −0 t/controller_Books.t
View
68 lib/Catalyst/Default/Controller/Books.pm
@@ -0,0 +1,68 @@
+package Catalyst::Default::Controller::Books;
+use Moose;
+use namespace::autoclean;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+Catalyst::Default::Controller::Books - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->response->body('Matched Catalyst::Default::Controller::Books in Books.');
+}
+
+=head2 list
+
+Fetch all book objects and pass to books/list.tt2 in stash to be displayed
+
+=cut
+
+sub list :Local {
+ # Retrieve the usual Perl OO '$self' for this object. $c is the Catalyst
+ # 'Context' that's used to 'glue together' the various components
+ # that make up the application
+ my ($self, $c) = @_;
+
+ # Retrieve all of the book records as book model objects and store in the
+ # stash where they can be accessed by the TT template
+ # $c->stash(books => [$c->model('DB::Book')->all]);
+ # But, for now, use this code until we create the model later
+ $c->stash(books => '');
+
+ # Set the TT template to use. You will almost always want to do this
+ # in your action methods (action methods respond to user input in
+ # your controllers).
+ $c->stash(template => 'books/list.tt2');
+}
+
+
+=head1 AUTHOR
+
+Phillip Smith
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
View
10 t/controller_Books.t
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+use Catalyst::Test 'Catalyst::Default';
+use Catalyst::Default::Controller::Books;
+
+ok( request('/books')->is_success, 'Request should succeed' );
+done_testing();
Please sign in to comment.
Something went wrong with that request. Please try again.