[Dancer-users] messed up routes

Mr. Puneet Kishor punk.kish at gmail.com
Thu Oct 20 18:28:39 CEST 2011


On Oct 20, 2011, at 11:22 AM, Richard Huxton wrote:

> On 20/10/11 17:13, Mr. Puneet Kishor wrote:
>> On Oct 20, 2011, at 10:47 AM, Naveed Massjouni wrote:
> 
>>> I think he was saying that you might have code in your apps such as:
>>>    set layout =>  'foo';
>>> This would set the layout globally and might have been the cause of your issue.
>> 
>> In that case, no, I never used `set layout =>  'foo'` anywhere in my code.
> > Only within specific routes, I used `layout 'foo'`.
> 
> But in your original example you had this:
> 
> > 	get '/*?' =>  sub {
> > 		..
> > 		debug "using layout main";
> > 		template 'index', \%template_opts;
> > 	}
> 
> That will end up with whatever layout the previous request set.
> 
> The layout is *not* per-request (unless you add it to the template call).
> 


Yes, this is the *only* potential problem spot that I could see, and I mentioned that in my subsequent email. I have not added a layout even to the default route instead of relying on the 'main' layout to be picked up automatically.

Here is the funny thing though -- I tested for that as well (yesterday, before I added the new code today). I requested a page which sent back the default layout correctly. Then I requested the page that sent back 'main_presentation' correctly. Then I requested the page with the default layout and that also came back correctly. In other words, I was unable to force an erroneous layout. And then, 10 mins later, bam, I requested the default page but it came back with the presentation layout. Then I hit Cmd-R 10 times and got the presentation layout (wrong layout) and then suddenly, bam, it reverted back to the default layout.

In fact, think this through -- if the above is really true, then once the non-default layout has been set (say, 'main_presentation') then the default 'main' layout should never be set for anyone because I wasn't explicitly setting the main layout. But, that wasn't the case as well.

I may never know the answer, but I can only hope that I don't encounter this unpredictable behavior.

--
Puneet Kishor


More information about the Dancer-users mailing list