Catalyst FAQ

General

How does Catalyst compare with Ruby on Rails?

See http://www.wikivs.com/wiki/Catalyst_vs_Ruby_on_Rails

What are the recommended modules to use with Catalyst for various tasks?

See Recommended Plugins

How do I use Unicode in my Catalyst application?

See Using Unicode

Where is the source? I want to submit diffs!

See Contributing.

Application architecture

How can I use Catalyst stuff from regular Perl scripts?

See Using Catalyst Models Externally but use Config::JFDI instead of the suggested "kludgy" solution.

Why do I get Caught exception in MyApp::Controller::Root->end "Catalyst::Action::RenderView could not find a view to forward to."?

Create a view using the myapp_create.pl view helper.

How do I set a default view?

One may configure a default view in their .conf or MyApp.pm. For example:

__PACKAGE__->config( default_view => 'TT' );

in MyApp.pm will make TT the default view. This works well in conjunction with:

sub end : ActionClass('RenderView') { }

which is often found in Root.pm.

How can I access $c->cache from a script?

Configuration

My new style myapp.conf isn't read, why?

Install Config::General. Try: cpan Config::General

What is the precedence of various configuration setting locations?

Settings are overridden in this order:

  1. MyApp/Model/Foo.pm
  2. MyApp.pm
  3. myapp.conf
  4. myapp_local.conf

This means that settings in myapp_local.conf will take precedence over all others.

Note also that in MyApp/Model/Foo.pm and MyApp.pm, any settings you define via __PACKAGE__->config(setting => $value) are read-only, class level defaults, which will be overridden by the configuration files.

After instantiating a Catalyst object, settings defined like

<Model::DBIC>
    foo = bar
</Model::DBIC>

will be available as: $c->model('DBIC')->{foo}, or more generally, $c->config->{'Model::DBIC'}->{foo}.

Debugging/profiling

How can I profile Catalyst code running in a fcgi environment using the -d perl profilers like Devel::NYTProf?

Fire a FastCGI kid up against the socket using perl -d

For other ways to profile your Catalyst code, see these threads by Jonathan Rockway: 1, 2.

See also Catalyst::Stats

How do I have my application e-mail me whenever there is an error?

What does the error screen below mean?

(en) Please come back later
(fr) SVP veuillez revenir plus tard
(de) Bitte versuchen sie es spaeter nocheinmal
(at) Konnten's bitt'schoen spaeter nochmal reinschauen
(no) Vennligst prov igjen senere
(dk) Venligst prov igen senere
(pl) Prosze sprobowac pozniej

It means an exception has occurred but debugging was disabled. Check the application error log for details. The error log may be stored in the server's error log, or if you followed deployment guidelines similar to those for lighttpd, it will be stored in a separate file.

You may also deliver a custom error message in this case, please see: Delivering a Custom Error Page

How do I hide certain variables (e.g. user/password) from the debug screen?

Q: I want to send someone the URL to myapp failing to get help with the error, but the debug shows a dumped hash with the username and password to my DB. How do I disable that?

A: In MyApp.pm, override $c->dump_these, which controls the variables to dump in the debug screen:

use MRO::Compat;
sub dump_these {
    my $c = shift;
    my @variables = $c->next::method(@_);
    return grep { $_->[0] ne 'Config' } @variables;
}

Q: I want to hide passwords sent as url/query/body parameters from the query table in the debug screen. How do I do that?

A: Use the CatalystX::DebugFilter role and filter the relevant parameters. In MyApp.pm:

with 'CatalystX::DebugFilter';
__PACKAGE__->config(
    'CatalystX::DebugFilter' => {
        Request => { params => [ 'password' ] },
    },
);

Database

How do I automatically create schema files for my database?

Use Catalyst::Helper::Model::DBIC::Schema. Assuming you have a myapp.db SQLite database, run

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static "dbi:SQLite:myapp.db"

For mySql Run

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:mysql:dbname:host.name.com 'username' 'password'

Is there some easy CRUD web interface that I can use with Catalyst?

See Catalyst::Plugin::AutoCRUD. If you have created the model and schema (see the previous question), all it takes is to add AutoCRUD to the list of plugins and browse to /autocrud.

How can I check whether my application has connected to the database?

You could do something like eval { $c->model('DB')->schema->storage->ensure_connected }; in Root::auto. ensure_connected doesn't do anything if you're already connected so this is not a performance issue. If you want to check just at the start, you can do __PACKAGE__->model('DB')->schema->storage->ensure_connected after ->setup in MyApp.pm.

Deployment

How should I ship/package my Catalyst application?

If you ship a tarball with your Catalyst app and a local::lib, all your customers need is perl

Why does Apache with FastCGI complain that it can't find my .tt2 files? (non-windows)

Try running the development server. If the templates render you most likely have a permissions problem that is preventing the Apache user from accessing your template files. Remember, the development server is run as yourself (the user you are logged in as) so permission problems may not be apparent until you roll out your site.

Using Catalyst::Engine::HTTP, my queries run fast locally, but from other computers, there's a huge pause before requests are satisfied - why?

Your DNS is likely borked - edit /etc/hosts (or c:\windows\system32\drivers\etc\hosts in Windows) to add the other computers' hostnames.
Solution 2: fix your DNS so other hosts resolve hostnames.

I want to use Catalyst to deploy an IPv6 aware application, how can I do it?

Catalyst does not have any problems with deployment of IPv6 aware applications, as long as it is done through an IPv6 aware HTTP engine (like Apache). However, the myapp_server script currently only listens on an IPv4 socket, and ignores any IPv6 addresses that your server may have.

In other words, testing is a bit more difficult than for IPv4, but there are no known problems with deployment of Catalyst IPv6 aware applications.

Miscellaneous

How to Roll Back a Distribution

Suppose you want to roll back a version of Catalyst because you think your current version may have a regression with regard to your application. You can do that by going to https://metacpan.org/release/Catalyst-Runtime and looking at the downloaded for the desired version. Then, at the cpan shell, run install [AUTHOR]/Catalyst-Runtime-[version].tar.gz.

For example, say you wanted to rollback to Catalyst::Runtime 5.80007:

cpan> install FLORA/Catalyst-Runtime-5.80007.tar.gz
My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker