Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Chained, root action, with default sub present

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


matija at serverflow

Aug 9, 2009, 7:31 AM

Post #1 of 6 (1418 views)
Permalink
Chained, root action, with default sub present

I think this may be either a bug or something I don't understand about
specifying chained actions.

Suppose I have a controller which has a defined default action (such as
created by catalyst.pl by default, i.e.


sub default :Path {
my ( $self, $c ) = @_;
$c->response->body( 'Page not found' );
$c->response->status(404);
}

To that I add a root action, the start of the chain, like so:

sub index :Chained('/') PathPart('') :Args(0) {
my ( $self, $c ) = @_;

# Hello World
$c->response->body( $c->welcome_message );
}

Now, whenever I request '/' from that script, default action triggers,
and the index action doesn't.
If I comment out the default action, the index DOES get called.

Is this a bug? If not, what do I have to change to have both index and
default in my root controller?

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


jshirley at gmail

Aug 9, 2009, 5:19 PM

Post #2 of 6 (1305 views)
Permalink
Re: Chained, root action, with default sub present [In reply to]

On Sun, Aug 9, 2009 at 7:31 AM, Matija Grabnar <matija [at] serverflow>wrote:

> I think this may be either a bug or something I don't understand about
> specifying chained actions.
>
> Suppose I have a controller which has a defined default action (such as
> created by catalyst.pl by default, i.e.
>
>
> sub default :Path {
> my ( $self, $c ) = @_;
> $c->response->body( 'Page not found' );
> $c->response->status(404);
> }
>
> To that I add a root action, the start of the chain, like so:
>
> sub index :Chained('/') PathPart('') :Args(0) {
> my ( $self, $c ) = @_;
>
> # Hello World
> $c->response->body( $c->welcome_message );
> }
>
> Now, whenever I request '/' from that script, default action triggers, and
> the index action doesn't.
> If I comment out the default action, the index DOES get called.
>
> Is this a bug? If not, what do I have to change to have both index and
> default in my root controller?
>

Hi Matija,

If you change the default attributes to "Private" it will do what you
expect. I think this may be a bug, though (thought this was fixed, but I
may be remembering wrong).

The index action should match "/" (though, in this circumstance you aren't
really chaining to anything, so it would make more sense to use sub index :
Path, which would do what you expect)

-Jay


matija at serverflow

Aug 10, 2009, 11:00 AM

Post #3 of 6 (1304 views)
Permalink
Re: Chained, root action, with default sub present [In reply to]

J. Shirley wrote:
> On Sun, Aug 9, 2009 at 7:31 AM, Matija Grabnar <matija [at] serverflow
> <mailto:matija [at] serverflow>> wrote:
>
> I think this may be either a bug or something I don't understand
> about specifying chained actions.
>
> Suppose I have a controller which has a defined default action
> (such as created by catalyst.pl by default, i.e.
>
>
> sub default :Path {
> my ( $self, $c ) = @_;
> $c->response->body( 'Page not found' );
> $c->response->status(404);
> }
>
> To that I add a root action, the start of the chain, like so:
>
> sub index :Chained('/') PathPart('') :Args(0) {
> my ( $self, $c ) = @_;
>
> # Hello World
> $c->response->body( $c->welcome_message );
> }
>
> Now, whenever I request '/' from that script, default action
> triggers, and the index action doesn't.
> If I comment out the default action, the index DOES get called.
>
> Is this a bug? If not, what do I have to change to have both index
> and default in my root controller?
>
>
> Hi Matija,
>
> If you change the default attributes to "Private" it will do what you
> expect. I think this may be a bug, though (thought this was fixed,
> but I may be remembering wrong).
Ah, not quite. Setting private on "default" does cause index to be
called when fetching "/", but now
default doesn't get called for unknown paths.
>
> The index action should match "/" (though, in this circumstance you
> aren't really chaining to anything, so it would make more sense to use
> sub index : Path, which would do what you expect)

To demonstrate the bug, I tried to make a minimal script that still
showed it. The original script, the one which led me to discover this
bug, was considerably bigger, and did indeed need / as part of the
chain. But there's no point in posting the whole, multi-controller beast
if I can demonstrate the bug with the most basic, two subroutine controller.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


frioux at gmail

Aug 10, 2009, 11:07 AM

Post #4 of 6 (1305 views)
Permalink
Re: Chained, root action, with default sub present [In reply to]

On Mon, Aug 10, 2009 at 1:00 PM, Matija Grabnar <matija [at] serverflow>wrote:

> J. Shirley wrote:
>
>> On Sun, Aug 9, 2009 at 7:31 AM, Matija Grabnar <matija [at] serverflow<mailto:
>> matija [at] serverflow>> wrote:
>>
>> I think this may be either a bug or something I don't understand
>> about specifying chained actions.
>>
>> Suppose I have a controller which has a defined default action
>> (such as created by catalyst.pl by default, i.e.
>>
>>
>> sub default :Path {
>> my ( $self, $c ) = @_;
>> $c->response->body( 'Page not found' );
>> $c->response->status(404);
>> }
>>
>> To that I add a root action, the start of the chain, like so:
>>
>> sub index :Chained('/') PathPart('') :Args(0) {
>> my ( $self, $c ) = @_;
>>
>> # Hello World
>> $c->response->body( $c->welcome_message );
>> }
>>
>> Now, whenever I request '/' from that script, default action
>> triggers, and the index action doesn't.
>> If I comment out the default action, the index DOES get called.
>>
>> Is this a bug? If not, what do I have to change to have both index
>> and default in my root controller?
>>
>>
>> Hi Matija,
>>
>> If you change the default attributes to "Private" it will do what you
>> expect. I think this may be a bug, though (thought this was fixed, but I
>> may be remembering wrong).
>>
> Ah, not quite. Setting private on "default" does cause index to be called
> when fetching "/", but now
> default doesn't get called for unknown paths.
>
>>
>> The index action should match "/" (though, in this circumstance you aren't
>> really chaining to anything, so it would make more sense to use sub index :
>> Path, which would do what you expect)
>>
>
> To demonstrate the bug, I tried to make a minimal script that still showed
> it. The original script, the one which led me to discover this bug, was
> considerably bigger, and did indeed need / as part of the chain. But there's
> no point in posting the whole, multi-controller beast if I can demonstrate
> the bug with the most basic, two subroutine controller.


I think the problem is that you have it defined as Chained. Is that what
you want? I think you just want

index : Path Args(0) { ... }

--
fREW Schmidt
http://blog.afoolishmanifesto.com


matija at serverflow

Aug 10, 2009, 12:56 PM

Post #5 of 6 (1299 views)
Permalink
Re: Chained, root action, with default sub present [In reply to]

fREW Schmidt wrote:
>
>
> On Mon, Aug 10, 2009 at 1:00 PM, Matija Grabnar <matija [at] serverflow
> <mailto:matija [at] serverflow>> wrote:
>
> J. Shirley wrote:
>
> On Sun, Aug 9, 2009 at 7:31 AM, Matija Grabnar
> <matija [at] serverflow <mailto:matija [at] serverflow>
> <mailto:matija [at] serverflow <mailto:matija [at] serverflow>>>
> wrote:
>
> I think this may be either a bug or something I don't
> understand
> about specifying chained actions.
>
> Suppose I have a controller which has a defined default action
> (such as created by catalyst.pl by default, i.e.
>
>
> sub default :Path {
> my ( $self, $c ) = @_;
> $c->response->body( 'Page not found' );
> $c->response->status(404);
> }
>
> To that I add a root action, the start of the chain, like so:
>
> sub index :Chained('/') PathPart('') :Args(0) {
> my ( $self, $c ) = @_;
>
> # Hello World
> $c->response->body( $c->welcome_message );
> }
>
> Now, whenever I request '/' from that script, default action
> triggers, and the index action doesn't.
> If I comment out the default action, the index DOES get called.
>
> Is this a bug? If not, what do I have to change to have
> both index
> and default in my root controller?
>
>
> Hi Matija,
>
> If you change the default attributes to "Private" it will do
> what you expect. I think this may be a bug, though (thought
> this was fixed, but I may be remembering wrong).
>
> Ah, not quite. Setting private on "default" does cause index to be
> called when fetching "/", but now
> default doesn't get called for unknown paths.
>
>
> The index action should match "/" (though, in this
> circumstance you aren't really chaining to anything, so it
> would make more sense to use sub index : Path, which would do
> what you expect)
>
>
> To demonstrate the bug, I tried to make a minimal script that
> still showed it. The original script, the one which led me to
> discover this bug, was considerably bigger, and did indeed need /
> as part of the chain. But there's no point in posting the whole,
> multi-controller beast if I can demonstrate the bug with the most
> basic, two subroutine controller.
>
>
> I think the problem is that you have it defined as Chained. Is that
> what you want? I think you just want
>
> index : Path Args(0) { ... }
With the default marked private, it doesn't get called whether index is
chained or not, so that doesn't help.

And yes, as I said above, this was just a minimal test case to
demonstrate the bug. The original script is bigger, and I think I have
stuff chaining off index there.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


pagaltzis at gmx

Aug 15, 2009, 10:22 PM

Post #6 of 6 (1218 views)
Permalink
Re: Chained, root action, with default sub present [In reply to]

* Matija Grabnar <matija [at] serverflow> [2009-08-09 16:35]:
> If not, what do I have to change to have both index and default
> in my root controller?

Do you *need* both in the same controller? Since you can attach
the root action of a Chained tree to any point in your URI space,
there is no need to have anything but a few infrastructure
actions in the ::Root controller. Mine has only the app-wide
`begin`, `default` and `end`, plus a `error404` action (for
forwarding to) and `login` and `logout`. Everything else is in
specific controllers, rather than in the catch-all ::Root, and
none of the other controllers have these special actions.

And that works perfectly.

This doesn’t *fix* the problem you found, of course – assuming
that it is a problem at all, and assuming it can even be fixed
at this point.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.