Now http://localhost:3000/hello prints "Hello World!".
-Note that actions with the C< :Global > attribute are equivalent to
+Note that actions with the C< :Local > attribute are equivalent to
using a C<:Path('action_name') > attribute, so our action could be
equivalently:
script/myapp_create.pl model MyModel DBIC::Schema MySchema create=static 'dbi:SQLite:/tmp/myapp.db'
-L<DBIx::Class::Schema::Loader> can automaticall load table layouts and
+L<DBIx::Class::Schema::Loader> can automatically load table layouts and
relationships, and convert them into a static schema definition
C<MySchema>, which you can edit later.
found, and automatically call the actions it finds that match the
circumstances of the request.
-The URL (for example http://localhost.3000/foo/bar) consists of two
+The URL (for example http://localhost:3000/foo/bar) consists of two
parts, the base, describing how to connect to the server
(http://localhost:3000/ in this example) and the path, which the
server uses to decide what to return (foo/bar). Please note that the
=item * B<Overriding the namespace>
-Note that __PACKAGE__->config->{namespace} can be used to override the
+Note that I<< __PACKAGE__->config->(namespace => ... ) >> can be used to override the
current namespace when matching. So:
package MyApp::Controller::Example;
would normally use 'example' as its namespace for matching, but if
this is specially overridden with
- __PACKAGE__->config->{namespace}='thing';
+ __PACKAGE__->config( namespace => 'thing' );
it matches using the namespace 'thing' instead.
use base 'Catalyst::Controller';
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
- __PACKAGE__->config->{namespace} = '';
+ __PACKAGE__->config( namespace => '');
sub default : Path {
my ( $self, $context ) = @_;
$context->response->status(404);
The code
- __PACKAGE__->config->{namespace} = '';
+ __PACKAGE__->config( namespace => '' );
makes the controller act as if its namespace is empty. As you'll see
below, an empty namespace makes many of the URL-matching attributes,
Matches any URL beginning with> http://localhost:3000/my/controller/foo. The namespace and
subroutine name together determine the path.
-=item * Namespace-level (C<:Global>)
+=item * Root-level (C<:Global>)
package MyApp::Controller::Foo;
sub foo : Global { }
Matches http://localhost:3000/foo - that is, the action is mapped
directly to the controller namespace, ignoring the function name.
-C<:Global> is equivalent C<:Local> one level higher in
-the namespace.
+C<:Global> always matches from root: it is sugar for C<:Path('/methodname')>.
+C<:Local> is simply sugar for C<:Path('methodname')>, which takes the package
+namespace as described above.
package MyApp::Controller::Root;
- __PACKAGE__->config->{namespace}='';
+ __PACKAGE__->config( namespace => '');
sub foo : Local { }
Use whichever makes the most sense for your application.
match precisely.
No :Args at all means that B<any number> of arguments are taken. Thus, any
-URL that B<starts with> the controller's path will match.
+URL that B<starts with> the controller's path will match. Obviously, this means
+you cannot chain from an action that does not specify args, as the next action
+in the chain will be swallowed as an arg to the first!
=item * Literal match (C<:Path>)