$ cd MyApp
This creates a similar skeletal structure to what we saw in Part 2 of
-the tutorial, except with C<MyApp> or C<myapp> substituted for
+the tutorial, except with C<MyApp> and C<myapp> substituted for
C<Hello> and C<hello>.
Enables the Catalyst debug output you saw when we started the
C<script/myapp_server.pl> development server earlier. You can remove
-this plugin when you place your application into production.
+this item when you place your application into production.
As you may have noticed, C<-Debug> is not a plugin, but a I<flag>.
Although most of the items specified on the C<use Catalyst> line of your
default format of YAML to the more straightforward C<Config::General>
format. Because Catalyst has long supported both formats, this
tutorial will simply use a configuration file called C<myapp.conf>
-instead of C<myapp.yml> and Catatlyst will automcatically use the new
+instead of C<myapp.yml> and Catalyst will automatically use the new
format. Just be aware that earlier versions of Catalyst will still
create the C<myapp.yml> file and that you will need to B<remove
C<myapp.yml>> and create a new C<myapp.conf> file by hand, but
Replace it with:
use Catalyst qw/
- -Debug
- ConfigLoader
- Static::Simple
-
- StackTrace
- /;
+ -Debug
+ ConfigLoader
+ Static::Simple
+
+ StackTrace
+ /;
This tells Catalyst to start using one new plugin:
components and provide access to Catalyst and plugin functionality.
B<TIP>: You may see the C<$c-E<gt>model('DB::Book')> used above
-written as C<$c-E<gt>model('DB')-E<gt>resultset('Book)>. The two
+written as C<$c-E<gt>model('DB')-E<gt>resultset('Book')>. The two
are equivalent.
B<Note:> Catalyst actions are regular Perl methods, but they make use
L<http://www.template-toolkit.org>). Other popular view technologies
include Mason (L<http://www.masonhq.com> and
L<http://www.masonbook.com>) and L<HTML::Template>
-(L<http://html- template.sourceforge.net>).
+(L<http://html-template.sourceforge.net>).
=head2 Create a Catalyst View Using C<TTSite>
application. Also take a look at C<lib/MyApp/View/TT.pm> for config
values set by the C<TTSite> helper.
-B<TIP>: Note that TTSite does one thing that could confuse people who
-are used to the normal C<TT> Catalyst view: it redefines the Catalyst
-context object in templates from its usual C<c> to C<Catalyst>. When
-looking at other Catalyst examples, remember that they almost always use
-C<c>. Note that Catalyst and TT I<do not complain> when you use the
-wrong name to access the context object...TT simply outputs blanks for
-that bogus logic (see next tip to change this behavior with TT C<DEBUG>
-options). Finally, be aware that this change in name I<only>
-applies to how the context object is accessed inside your TT templates;
-your controllers will continue to use C<$c> (or whatever name you use
-when fetching the reference from C<@_> inside your methods). (You can
-change back to the "default" behavior be removing the C<CATALYST_VAR>
-line from C<lib/MyApp/View/TT.pm>, but you will also have to edit
-C<root/lib/config/main> and C<root/lib/config/url>. If you do this, be
-careful not to have a collision between your own C<c> variable and the
-Catalyst C<c> variable.)
-
B<TIP>: When troubleshooting TT it can be helpful to enable variable
C<DEBUG> options. You can do this in a Catalyst environment by adding
a C<DEBUG> line to the C<__PACKAGE__->config> declaration in
C<lib/MyApp/View/TT.pm>:
__PACKAGE__->config({
- CATALYST_VAR => 'Catalyst',
...
DEBUG => 'undef',
...
C<__PACKAGE__> is equivalent to C<TT>.
There are a variety of options you can use, such as 'undef', 'all',
-'service', 'context', 'parser', 'provider', and 'service'. See
+'service', 'context', 'parser' and 'provider'. See
L<Template::Constants> for more information (remove the C<DEBUG_>
portion of the name shown in the TT docs and convert to lower case
for use inside Catalyst).
As indicated by the inline comments above, the C<META title> line uses
TT's META feature to provide a title to C<root/lib/site/header>.
-Meanwhile, the outer C<FOREACH> loop iterates through each C<book> model
-object and prints the C<title> and C<rating> fields. An inner
-C<FOREACH> loop prints the last name of each author in a comma-separated
-list within a single table cell.
+Meanwhile, the C<FOREACH> loop iterates through each C<book> model
+object and prints the C<title> and C<rating> fields.
If you are new to TT, the C<[%> and C<%]> tags are used to delimit TT
code. TT supports a wide variety of directives for "calling" other
usual range of Perl operators down to the single dot (C<.>) operator.
This applies to operations as diverse as method calls, hash lookups, and
list index values (see
-L<http://www.template-toolkit.org/docs/default/Manual/Variables.html>
+L<http://search.cpan.org/perldoc?Template::Manual::Variables>
for details and examples). In addition to the usual C<Template> module
Pod documentation, you can access the TT manual at
-L<http://www.template-toolkit.org/docs/default/>.
+L<http://search.cpan.org/perldoc?Template::Manual>.
B<NOTE:> The C<TTSite> helper creates several TT files using an
extension of C<.tt2>. Most other Catalyst and TT examples use an
because we enabled DBIC_TRACE.
-You now the beginnings of a simple but workable web application.
+You now have the beginnings of a simple but workable web application.
Continue on to future sections and we will develop the application
more fully.
One option would be to create a separate schema file for each table in
the database, however, lets use the same L<DBIx::Class::Schema::Loader>
used earlier with C<create=dynamic> to build the static files for us.
-First, lets remove the schema file created in Part 2:
+First, lets remove the schema file created earlier:
$ rm lib/MyApp/Schema.pm
<td>
[% # First initialize a TT variable to hold a list. Then use a TT FOREACH -%]
[% # loop in 'side effect notation' to load just the last names of the -%]
- [% # authors into the list. Note that the 'push' TT vmethod does not -%]
+ [% # authors into the list. Note that the 'push' TT vmethod does not print -%]
[% # a value, so nothing will be printed here. But, if you have something -%]
[% # in TT that does return a method and you don't want it printed, you -%]
[% # can: 1) assign it to a bogus value, or 2) use the CALL keyword to -%]
[% tt_authors.join(', ') | html %]
</td>
-Then hit C<Ctrl+R> in your browser (not that you don't need to reload
+Then hit C<Ctrl+R> in your browser (note that you don't need to reload
the development server or use the C<-r> option when updating TT
-templates) and you should now the the number of authors each book and
-a comma-separated list of the author's last names.
+templates) and you should now see the number of authors each book has
+along with a comma-separated list of the authors' last names.
If you are still running the development server with C<DBIC_TRACE>
enabled, you should also now see five more C<SELECT> statements in the
L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>.
Copyright 2006-2008, Kennedy Clark, under Creative Commons License
-(L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).
+(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).