[Catalyst] sub default :Private versus sub xxx :Path

Ash Berlin ash at cpan.org
Tue Jul 11 17:35:37 CEST 2006


John Napiorkowski wrote:
> With Catalyst we now have three ways to hook an action to the package namespace (That I know of)
>
> package myapp::Controller::demo
>
> 1) sub default :Private {...}
> 2) sub index :Private {...}
> 3) sub xxxxx :Path {...}
>
> All the above match /demo and 1,3 match /demo/arg1/arg2, etc while 2 doesn't.
>
> Now I know from the documentation that the primary function difference are in execution precedence 
> and in the way they capture arguments.  I can see an advantage to the sub xxxx :Path way over sub default
> because this way I can give my root actions a meaningful private name.  However I was wondering what
> other reasons might people use sub xxxx :Path over sub default?  I'm just trying to put together a best
> practices guide for new developers and this one I've been scratching my head over. Maybe we haven't figured 
> out the best way to use all these great new features yet but I just wanted to here what other people thought.
>
> -john
>
>
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>   
All for /controller/foo/bar

sub default : Private {
    my ($self, $c, @args) = @_;
    # args = qw/controller foo bar/

}

sub xxxx : Path {
    my ($self, $c, @args) = @_;
    # args = qw/foo bar/;
}

I personally only use default for 404 handlers.

Also you should take a look at the :Chained attribute.

Ash




More information about the Catalyst mailing list