close to a working app.) It is not designed for end users, but for
working programmers.
-=head2 Some background
-
=head2 Web programming: The Olden Days
Perl has long been favored for web applications. There are a wide
if ( $c->request->parameters->{form_submit} eq 'yes' ) {
if ( my $upload = $c->request->upload('my_file') ) {
-
+
my $filename = $upload->filename;
my $target = "/tmp/upload/$filename";
-
+
unless ( $upload->link_to($target) || $upload->copy_to($target) ) {
die( "Failed to copy '$filename' to '$target': $!" );
}
}
}
-
+
$c->stash->{template} = 'file_upload.html';
}
my $upload = $c->req->upload($field);
my $filename = $upload->filename;
my $target = "/tmp/upload/$filename";
-
+
unless ( $upload->link_to($target) || $upload->copy_to($target) ) {
die( "Failed to copy '$filename' to '$target': $!" );
}
For more information see the FastCGI documentation, the C<FCGI> module
and L<http://www.fastcgi.com/>.
-
+
=head2 Serving static content
Serving static content in Catalyst can be somewhat tricky; this recipe
# serve all files under /static as static files
sub default : Path('/static') {
my ( $self, $c ) = @_;
-
+
# Optional, allow the browser to cache the content
$c->res->headers->header( 'Cache-Control' => 'max-age=86400' );
# also handle requests for /favicon.ico
sub favicon : Path('/favicon.ico') {
my ( $self, $c ) = @_;
-
+
$c->serve_static;
}
use lib qw(/var/www/MyApp/lib);
</Perl>
PerlModule MyApp
-
+
<VirtualHost *>
ServerName myapp.example.com
DocumentRoot /var/www/MyApp/root
$c->req->args([qw/arg1 arg2 arg3/]);
$c->forward('/wherever');
-(See L<Catalyst::Manual::Intro#Flow_Control> for more information on
-passing arguments via C<forward>.)
+(See the L<Catalyst::Manual::Intro> Flow_Control section for more
+information on passing arguments via C<forward>.)
=head2 Configure your application
sub end : Private {
my ( $self, $c ) = @_;
-
+
if ( scalar @{ $c->error } ) {
$c->stash->{errors} = $c->error;
$c->stash->{template} = 'errors.tt';
$c->forward('MyApp::View::TT');
$c->error(0);
}
-
+
return 1 if $c->response->status =~ /^3\d\d$/;
return 1 if $c->response->body;
-
+
unless ( $c->response->content_type ) {
$c->response->content_type('text/html; charset=utf-8');
}
-
+
$c->forward('MyApp::View::TT');
}
$c->request->param('username'),
$c->request->param('password'),
);
-
+
# if login() returns 1, user is now logged in
$c->response->redirect('/some/page');
}
my $first_argument = $c->req->args[0]; # now = 'test1'
# do something...
}
-
+
As you can see from these examples, you can just use the method name as
long as you are referring to methods in the same controller. If you want
to forward to a method in another controller, or the main application,
name => 'My Application',
root => '/home/joeuser/myapp/root'
);
-
+
__PACKAGE__->setup;
sub end : Private {
=head2 Catalyst::Plugin::Account::AutoDiscovery
-L<Catalyst Plugin for Account Auto-Discovery> provides Account Auto-Discovery
+L<Catalyst::Plugin::Account::AutoDiscovery> provides Account Auto-Discovery
for Catalyst.
=head2 Catalyst::Plugin::Acme::Scramble
L<Catalyst::Plugin::Authentication::Credential::Atom> is a plugin which
implements WSSE and Basic authentication for Catalyst applications using
-L<Catalyst::Plugin:AtomServer>
+L<Catalyst::Plugin::AtomServer>
=head2 Catalyst::Plugin::Authentication::Credential::Flickr
=head2 Catalyst::Plugin::Authentication::Simple
-Replaced by new L<Catalyst::Plugin::Authentication framework>
+Replaced by new L<Catalyst::Plugin::Authentication> framework
=head2 Catalyst::Plugin::Authentication::Store
skeleton application for you:
$ catalyst MyApp
-
+
created "MyApp"
created "MyApp/script"
created "MyApp/lib"
+--------------------------------------+---------------------------------------+
| /default | MyApp |
'--------------------------------------+---------------------------------------'
-
+
[...] [catalyst] [info] MyApp powered by Catalyst 5.5
You can connect to your server at http://localhost:3000
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
-
+
HTTP/1.0 200 OK
Date: Mon, 07 Nov 2005 14:57:39 GMT
Content-Length: 5525
=head2 Debugging
The simplest way to debug your Catalyst application is to run it using
-the built-in mini-server as described in L</Getting Started>.
+the built-in mini-server as described in L<Getting started>.
If you want to output any debugging information to the console, then
call C<< $context->log->debug() >>, passing it a string to output. For
done. Only one end action will be called, if there is one in a
controller, it will be prefered over one in the application module, and
so on.
-
+
Since we're writing a simple application, just add an end action like
this to F<tutorial.pm>:
$c->NEXT::handler-name( @_ );
if you already C<shift>ed it out of C<@_>. Remember to C<use> C<NEXT>.
-
+
=head2 Storage and Configuration
Some Plugins use their accessor names as a storage point, e.g.
to add a unique ID to every request:
package Catalyst::Plugin::RequestUUID;
-
+
use warnings;
use strict;
-
+
use Catalyst::Request;
use Data::UUID;
use NEXT;
our $VERSION = 0.01;
-
+
{ # create a uuid accessor
package Catalyst::Request;
__PACKAGE__->mk_accessors('uuid');
sub prepare {
my $class = shift;
-
+
# Turns the engine-specific request into a Catalyst context .
my $c = $class->NEXT::prepare( @_ );