[Catalyst] Error handling

Albert Vila avp at imente.com
Mon Oct 24 19:06:46 CEST 2005


 I have a problem trying to configure my catalyst application in order 
to do the error handling in the begin method.

 I have a controller with multiple functions, each function receives the 
same parameter, and I wanna check the parameter integrity in just one place.

 Now, my functions looks like:
    sub function: Local {
       my ( $self, $c ) = @_;

       if ($c->req->param('parameter') eq '') {
          //do stuff
       } else {

 I wanna achieve something like:

    sub function: Local {
       my ( $self, $c ) = @_;

        //do stuff

    sub begin : Private {
        my ($self, $c) = @_;
        my $error = undef;

        # Verifiquem tots els paràmetres q ens poden entrar
        foreach my $key (keys %{$c->req->params}) {
            my $value = $c->req->param($key);
            if ($value eq '') {
                $error =  1;

        if (defined $error) {

    This solution does not work because catalyst continues running the 
whole flow process.

    Am I doing something wrong?, Any suggestion?

    Another question, Is it possible to have urls like 
localhost:3000/controller/method/parameter all managed by the same Regex?

       For example:
          Package controller;

          sub integrity: Regex ('_xx/_yy') {
             my ($self, $c) = @_;

             # Check the integrity for the yy parameter
             # If everything is fine then forward to method xx
       With this solution you can have only one generic Regex that 
handles the errors and if all is ok redirects to the requested action. 
This save time and code because you don't have to duplicate the error 
check if every Regex function. Than only works in my case that I have 
only one parameter used in many functions in the same controller.



More information about the Catalyst mailing list