[Catalyst] Why is $c undefined?

will trillich will.trillich at serensoft.com
Mon Oct 29 19:16:37 GMT 2012


On Mon, Oct 29, 2012 at 2:07 PM, Craig Chant
<craig at homeloanpartnership.com>wrote:

>  sub begin :Private {
>
>
>
>     my ( $self, $c ) =3D @_;
>
>
>
>     # Authenticate
>
>     $self->AuthenticateUser();
>

*Note, you don't pass $c to AuthenticateUser here!*



>      return 1;
>
>
>
> }
>
>
>
> I then have...
>
>
>
> sub AuthenticateUser {
>
>
>
>     my ( $self, $c ) =3D @_;
>
>
>
>     $c->session;
>
>     if(!$c->model('Members')->LogCheck($c)){
>
>         $c->uri_for_action('/login/login');
>
>     }
>
>
>
> }
>
>
>
> However, $c is undefined and errors, it only works if I pass it $c from
> 'begin'..
>
>
>
>     $self->AuthenticateUser($c);
>
>
>
>
>
> I was under the impression that $c was the context (Catalyst) default
> variable and was always passed to every method / subroutine.
>
>
>
> is this not the case?
>

*Right, that's not the case. It only passes to the :Chained or :Args or
:CaptureArgs methods. This leaves you free to create your own internal
methods that don't get extra $c args interfering with your logic.*
*
*

-- =

 Will Trillich :: 812.454.6431

=93Grading takes away all the fun from failing. And a huge part of education
is about failure.=94  -- Shimon Schocken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20121029/0048e=
c38/attachment.htm


More information about the Catalyst mailing list