Monks,

I'm trying to follow the tutorial in Jonathan Rockway's talk from OSCON 2007 titled Catalyst in 5 minutes. I'm intrigued by the flexibility Catalysts offers, but apart from the very first splash 'Hello world' page, I'm unable to get his sample up and running. Any help on how to resolve the below issue is appreciated. Apologies for the excessive contents.

# lib/Blog/Controller/Root.pm package Blog::Controller::Root; use strict; use warnings; use base 'Catalyst::Controller::BindLex'; __PACKAGE__->config->{namespace} = ''; sub all_posts : Path : Args(0) { my ($self, $c) = @_; my @posts : Stashed = $c->model('DBIC::Posts')->search( {}, { order_by => 'posted DESC', rows => 5, page => 1, } ); } sub end : ActionClass('RenderView') { }
# lib/Blog/View/TD/Main.pm package Blog::View::TD::Main; use strict; use warnings; use Template::Declare::Tags; sub wrapper(&) { my $content = shift; smart_tag_wrapper { html { head { title { c->stash->{title}; }; }; body { h1 { c->stash->{title} }; $content->(); } } } } template all_posts => sub { c->stash->{title} = 'Blog posts'; wrapper { foreach my $post (@{c->stash->posts||[]}) { div { attr { class => 'post' }; h2 { $post->title }; p { 'Written by ' . $post->author}; }; div { attr { class => 'body'}; outs_raw($post->body); # bad } } } }; 1; __END__
# lib/Blog/Model/DBIC.pm package Blog::Model::DBIC; use strict; use base 'Catalyst::Model::DBIC::Schema'; __PACKAGE__->config( schema_class => 'Blog::Schema', connect_info => [ 'DBI:SQLite:root/catalyst', ], ); 1;
Model and Schema created as follows:
# Create Schema perl script/blog_create.pl model DBIC DBIC::Schema Blog::Schema create +=static DBI:SQLite:root/catalyst # Create View perl script/blog_create.pl view TD Template::Declare
Edit Makefile.PL and make:
# Edit Makefile.PL $ diff Makefile.PL~ Makefile.PL 5a6,7 > requires 'Catalyst::Model::DBIC::Schema'; > requires 'Catalyst::View::Template::Declare'; perl Makefile.PL sudo make installdeps sudo make test
I start the local web-server:
$ perl script/blog_server.pl -r -d [debug] Debug messages enabled [debug] Loaded plugins: .----------------------------------------------------. | Catalyst::Plugin::ConfigLoader 0.18 | | Catalyst::Plugin::Static::Simple 0.20 | '----------------------------------------------------' [debug] Loaded dispatcher "Catalyst::Dispatcher" [debug] Loaded engine "Catalyst::Engine::HTTP::Restarter" [debug] Found home "/home/foo/test/perl/catalyst/blog/Blog" [debug] Loaded Config "/home/foo/test/perl/catalyst/blog/Blog/blog.yml +" [info] Loading subtemplate Blog::View::TD::Main [debug] Loaded components: .-----------------------------------------+----------. | Class | Type | +-----------------------------------------+----------+ | Blog::Controller::Root | instance | | Blog::Model::DBIC | instance | | Blog::View::TD | instance | | Blog::View::TD::Main | class | '-----------------------------------------+----------' [debug] Loaded Private actions: .----------------------+------------------------+--------------. | Private | Class | Method | +----------------------+------------------------+--------------+ | /end | Blog::Controller::Root | end | | /all_posts | Blog::Controller::Root | all_posts | '----------------------+------------------------+--------------' [debug] Loaded Path actions: .-------------------------------------+-------------. | Path | Private | +-------------------------------------+-------------+ | / | /all_posts | '-------------------------------------+-------------' [info] Blog powered by Catalyst 5.7011 You can connect to your server at http://localhost:3000
Opening the url in a web browser yields:
[info] *** Request 1 (0.027/s) [17489] [Mon Oct 22 15:29:38 2007] *** [debug] "GET" request for "/" from "127.0.0.1" [debug] Path is "/" [error] Caught exception in Blog::Controller::Root->all_posts "Can't c +all method "search" on an undefined value at /home/foo/test/perl/cata +lyst/blog/Blog/script/../lib/Blog/Controller/Root.pm line 11." [info] Request took 0.239138s (4.182/s) .----------------------------------------+-----------. | Action | Time | +----------------------------------------+-----------+ | /all_posts | 0.000361s | | /end | 0.002197s | '----------------------------------------+-----------'
Update: I've created the database entries manually as suggested by lorn, but I still get the same error.
$ sqlite3 root/database SQLite version 3.3.6 Enter ".help" for instructions sqlite> .tables posts sqlite> .schema posts CREATE TABLE posts (id integer primary key, title text not null, body +text not null, author text not null, posted date not null); sqlite> select * from posts; 1|test|a new post|Foo|2007-01-01 00:01 2|another test|another post|Bar|2007-01-01 00:02 sqlite>
--
Andreas

In reply to Basic question on "Catalyst in 5 minutes" by andreas1234567

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.