Re: Straight templates (Was: Re: [Maypole] model_class issues on 1.7->2.x upgrade?)

From: Simon Flack (sf at flacks.net)
Date: Sat Dec 04 2004 - 16:20:52 GMT


On Fri, 3 Dec 2004 23:20:23 -0500, Jesse Sheidlower wrote
> On Thu, Nov 18, 2004 at 01:03:36PM -0800, Peter Speltz wrote:
> >
> > --- Jesse Sheidlower <jester at panix.com> wrote:
> >
> > >
> > > Before I spend too much time debugging this, I thought someone
> > > might have run into this and could help out.
> > >
> > > I just upgraded Maypole from 1.7 to 2.04. Several applications
> > > were unaffected, but one relatively complex one, which has some
> > > authentication juju going on, had problems. I'm now throwing
> > > errors of the sort:
> > >
> > > caught authenticate error: Can't call method "can" on an undefined
> > > value at...
> > >
> > > with the relevant line, in the main module, being
> > >
> > > return $r->model_class->sub_authenticate($r)
> > > if $r->model_class->can("sub_authenticate");
> > >
> >
> > What's the main module? You're driver? Are you going to a page that doesn't

Indeed, is that code in your driver, or are you referring to
call_authenticate() in Maypole.pm? If it's the former, that's your problem.

> > have a model class associated with it like a straight template? Wrap above
> > code in an "if ($r->model_class) { warn "No model classs in sub authenticate;
> > .. . } and see if everything works ok. Check error log for warnings and see
> > what situations you get the warning.
>
> Just coming back to this after some time working on the real $JOB.
>
> Indeed, this was only happening on the frontpage template; anything
> associated with a model class works fine.
>
> Which leads me to two questions:
>
> 1. What changed from 1.7 to 2.x so that visiting such a page no
> longer works, and more to the point what do I need to do under 2.x
> so that visits to such a page don't fail? Is there a way to default
> things to the base model class if there's no other?

2.x authenticates plain templates but 1.7 didn't. But that shouldn't cause a
problem in itself, it depends what your authenticate() method is doing.

When Maypole is given a request that doesn't have a model, or the action isn't
public, $r->model_class is undefined. So if you're calling a method on
$r->model_class in your authenticate() method, you need to check that there is
a model_class first.

BTW, Maypole checks to see if there's a model_class->authenticate() and if so,
calls it before calling $r->authenticate. So you shouldn't need to do that
yourself in your driver's authenticate() method.

> 2. I hadn't realized you can deliberately go to a straight template
> page. In my apps when I have a plain template, I've been doing
> things like:
>
> sub about_this_site :Exported {
> my ($self, $r);
> $r->{template} = "about_this_site";
> }
>
> But perhaps there's a much better way.

Yes, if your authenticate() method returns OK for requests that don't have a
model_class, you can remove that method and Maypole should take care of it.

> Thanks.
>
> Jesse Sheidlower
>
> _______________________________________________
> maypole mailing list
> maypole at lists.netthink.co.uk
> http://lists.netthink.co.uk/listinfo/maypole

--simonflk

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT