[Catalyst-dev] Re: Quick Catalyst::Plugin::SubRequest notes

Aristotle Pagaltzis pagaltzis at gmx.de
Mon Mar 3 22:01:27 GMT 2008


* Ash Berlin <ash_cpan at firemirror.com> [2008-03-03 12:05]:
> On 3 Mar 2008, at 10:53, Aristotle Pagaltzis wrote:
>> 2. An `is_subrequest` query method that, obviously enough,
>>   returns true during a subrequest.
>
> Why do you need this? The whole point of subreq (as I
> understand it) is that it looks like a normal request.

In my case, there are various authorisation checks in the code
that is invoked via subrequest that I want to relax. Since the
superrequest has already done its auth checks when it decides
to make the subrequest, the subrequest comes from a trusted path.

I could do this without ::SubRequest’s aid by passing a flag via
the passed-in stash. But then I’d want to sugarify this, so in
the end I’d have an `is_subreq` in MyApp.pm anyway, only it would
check a stash flag. And I’d also need need to wrap `subreq` in
MyApp.pm to always set the stash flag on the passed-in stash.

That’s not much work, admittedly, but considering how easy it is
to write `subreq` if you’re willing to peek under the hood, why
bother with the extra monkey work?

    sub is_subreq {
        my $self = shift;
        ref $self->engine eq
        'Catalyst::Plugin::SubRequest::Internal::FakeEngine';
    }

But in MyApp.pm, that’s a hack. It uses knowledge of ::SubRequest
internals that aren’t advertised.

The exact same code in SubRequest.pm would be legit.

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



More information about the Catalyst-dev mailing list