[Catalyst] Dispatcher: auto called twice on default calls.

Bill Moseley moseley at hank.org
Mon May 1 00:37:41 CEST 2006


Someone that knows the dispatcher will need to help.

Auto is called twice for default actions:

    $ cat lib/My.pm 
    package My;
    use strict;
    use Catalyst;

    My->config( name => 'My' );
    My->setup;

    sub auto : Private {
        my ( $self, $c ) = @_;
        warn "in auto - ", ++$c->stash->{auto}, "\n";
        return 1;
    }

    sub default : Private {
        my ( $self, $c ) = @_;
        warn "in default - ", ++$c->stash->{default}, "\n";
        $c->res->body( 'This is body' );
        $c->res->content_type('text/plain');
    }

    1;

    $ script/my_test.pl /fooskdkd
    in auto - 1
    in auto - 2
    in default - 1
    This is body

In the dispatcher there's this code:


    sub get_containers {
        my ( $self, $namespace ) = @_;
        $namespace ||= '';
        $namespace = '' if $namespace eq '/';

        my @containers;

        do {
            push @containers, $self->container_hash->{$namespace};
        } while ( $namespace =~ s#/[^/]+$## );

        return reverse grep { defined } @containers, $self->container_hash->{''};

        my @parts = split '/', $namespace;
    }

Doesn't it look like:

1) if namespace = '' then the returned list will be duplicated?
   (which is why auto is being called twice)

2) that a namespace of /0 (zero) is not allowed?
   Perhaps:

    $namespace = '' unless defined $namespace;

   If that's the intent.


3) not evident here, but can $namespace ever = '/'?  Or undefined for
   that matter?

4) @parts is very lonely.

I could provide a patch, but I'm not very clear how the dispatcher is
suppose to work, and due to the self documenting code, not really
clear about the intent of the existing code, either.

Maybe:

    unless ( $namespace eq '' ) {
        do {
                push @containers, $self->container_hash->{$namespace};
        } while ( $namespace =~ s#/[^/]+$## );
    }

Or:

    push @containers, $self->container_hash->{''} unless
        $start_namespace eq '';
    return reverse grep { defined } @containers;

Although I'm not sure about that defined either.

So, I defer to the authors.


Thanks,


-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list