[Catalyst] Why is $c undefined?

Craig Chant craig at homeloanpartnership.com
Mon Oct 29 19:29:38 GMT 2012


Thanks Will,



Appreciate you clarifying this for me.



CRaig.

________________________________
From: will trillich [will.trillich at serensoft.com]
Sent: 29 October 2012 19:16
To: The elegant MVC web framework
Subject: Re: [Catalyst] Why is $c undefined?

On Mon, Oct 29, 2012 at 2:07 PM, Craig Chant <craig at homeloanpartnership.com=
<mailto: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 'be=
gin'..

    $self->AuthenticateUser($c);


I was under the impression that $c was the context (Catalyst) default varia=
ble 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 :Cap=
tureArgs methods. This leaves you free to create your own internal methods =
that don't get extra $c args interfering with your logic.


--
[http://www.serensoft.com/sites/all/themes/marinelli/img/serensoft_logo_scr=
een.gif] Will Trillich :: 812.454.6431

=93Grading takes away all the fun from failing. And a huge part of educatio=
n is about failure.=94  -- Shimon Schocken
This Email and any attachments contain confidential information and is inte=
nded solely for the individual to whom it is addressed. If this Email has b=
een misdirected, please notify the author as soon as possible. If you are n=
ot the intended recipient you must not disclose, distribute, copy, print or=
 rely on any of the information contained, and all copies must be deleted i=
mmediately. Whilst we take reasonable steps to try to identify any software=
 viruses, any attachments to this e-mail may nevertheless contain viruses, =
which our anti-virus software has failed to identify. You should therefore =
carry out your own anti-virus checks before opening any documents. HomeLoan=
 Partnership will not accept any liability for damage caused by computer vi=
ruses emanating from any attachment or other document supplied with this e-=
mail. HomeLoan Partnership reserves the right to monitor and archive all e-=
mail communications through its network. No representative or employee of H=
omeLoan Partnership has the authority to enter into any contract on behalf =
of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of=
 H L Partnership Limited, registered in England and Wales with Registration=
 Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L=
 Partnership Limited is authorised and regulated by the Financial Services =
Authority.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20121029/32c35=
ffb/attachment.htm


More information about the Catalyst mailing list