RE: [Catalyst] Why is $c undefined?

2012-10-30 Thread Craig Chant
Thanks Ian,

The hierarchy is something that I am finding mind-blowing at the moment,
$self-jqgrid-render($self, , you are calling methods jqgrid-render on 
$self, passing in $self, I'm sure it makes sense to you :-)

One thing I would like clarification with if possible.

Where do I put code that requires the use of more than one model?

Do I create a separate model that acts as an interface between the other models?

You see I have two SQL servers in opposite ends of the country and so I have a 
model built on Model::DBI that can access one server and another Model that can 
access the other, but I have functionality that needs data from both , do some 
calculations and output accordingly.

I assume this does not go in the controller, but I create an interface model 
with the required methods and functionality that the controller uses?

Regards,

Craig.

-Original Message-
From: Ian Docherty [mailto:catal...@iandocherty.com]
Sent: 30 October 2012 07:22
To: The elegant MVC web framework
Subject: Re: [Catalyst] Why is $c undefined?

On 29 October 2012 21:01, Craig Chant cr...@homeloanpartnership.com wrote:
...

 I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
 the Model and move alot of functionality to the Controller, so there is a 
 paradigm which seems to imply it is ok to do more stuff in the Controller, 
 but I am leaning towards having the main code in the Model and then bolting 
 it together via the Controller.

I can understand why you get this impression, I think a lot of people end up 
putting code in the Controller when they first start using MVC (I did so myself 
in the past).

The Model should be external to your Catalyst app (or whatever framework you 
use) so that you can use it in things like cron jobs. It also makes testing 
easier if your Model is separate from your Catalyst app. Look at using 
something like Catalyst::Model::Adaptor as a thin shell to add your external 
Model into Catalyst.

I am moving more and more into making my Controllers as thin as possible. Logic 
that I might have previously put into the Controller, I either put into the 
Model or I create helper functions. Here is an example of a Controller (from 
Mojolicious as it happens but that is not important)

sub user_list {
my ($self) = @_;

$self-jqgrid-render($self, {
rs  = $self-schema-resultset('User')-search_rs,
filters = {},
rows= [qw(id name)],
});
}

It's not important to know what is going on here, but this Controller gets a 
list of all users, formats the data for use in the jQuery jqGrid allows for 
sorting and filtering and outputs the data in JSON format. The point being, the 
controller code is kept simple and 'thin'
and yet it does a lot of work behind the scenes.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
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 viruses 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 HomeLoan 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.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Ian Docherty
On 30 October 2012 11:09, Craig Chant cr...@homeloanpartnership.com wrote:
 Thanks Ian,

 The hierarchy is something that I am finding mind-blowing at the moment,
 $self-jqgrid-render($self, , you are calling methods jqgrid-render on 
 $self, passing in $self, I'm sure it makes sense to you :-)

 One thing I would like clarification with if possible.

 Where do I put code that requires the use of more than one model?

 Do I create a separate model that acts as an interface between the other 
 models?

 You see I have two SQL servers in opposite ends of the country and so I have 
 a model built on Model::DBI that can access one server and another Model that 
 can access the other, but I have functionality that needs data from both , do 
 some calculations and output accordingly.

 I assume this does not go in the controller, but I create an interface model 
 with the required methods and functionality that the controller uses?

Craig. Yes, try to keep it out of the Controller.

My opinion is, that if you have business logic that uses data from two
SQL servers (each of which has it's own model) then this would be a
model in it's own right. First think of this business logic outside of
Catalyst, it might have accessors for each of the SQL instance
objects. Create a BusinessModel for this logic. You might find that
this then becomes the only Model that you need to access from
Catalyst, and the SQL server objects are not directly called from
Catalyst, but are subsumed by BusinessModel.

Then use Catalyst::Model::Adaptor with your BusinessModel giving
Catalyst access to all of it's methods.

Kind Regards
Ian

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Lukas Thiemeier
Hi Craig,

On 10/30/2012 12:09 PM, Craig Chant wrote:
 Thanks Ian,
 
 The hierarchy is something that I am finding mind-blowing at the moment,
 $self-jqgrid-render($self, , you are calling methods jqgrid-render on 
 $self, passing in $self, I'm sure it makes sense to you :-)
 

No, he is calling render on whatever is returned by $self-jqgrid.
Thats why $self has to be passed to render. The code above is
equivalent to:

  my $jqgrid = $self-jqgrid;
  $jqgrid-render($self, ...);


 One thing I would like clarification with if possible.
 
 Where do I put code that requires the use of more than one model?
 
 Do I create a separate model that acts as an interface between the other 
 models?

Thats one possibility. Another possibility would be to create a helper
method in Model1, which expects Model2 as a parameter.

Model1.pm:

  sub calculate_sth_with_model2{
my ($self, $model2) = @_;
do_crazy_calculations();
  }

And in your Controller:

  sub calculate :Local :Args(0) {
my ($self, $c) = @_;

my $m1 = $c-model(Model1);
my $m2 = $c-model(Model2);

$m1-calculate_sth_with_model2($m2);

  }

 
 You see I have two SQL servers in opposite ends of the country and so I have 
 a model built on Model::DBI that can access one server and another Model that 
 can access the other, but I have functionality that needs data from both , do 
 some calculations and output accordingly.
 
 I assume this does not go in the controller, but I create an interface model 
 with the required methods and functionality that the controller uses?
 
 Regards,
 
 Craig.
 
 -Original Message-
 From: Ian Docherty [mailto:catal...@iandocherty.com]
 Sent: 30 October 2012 07:22
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] Why is $c undefined?
 
 On 29 October 2012 21:01, Craig Chant cr...@homeloanpartnership.com wrote:
 ...

 I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
 the Model and move alot of functionality to the Controller, so there is a 
 paradigm which seems to imply it is ok to do more stuff in the Controller, 
 but I am leaning towards having the main code in the Model and then bolting 
 it together via the Controller.

 I can understand why you get this impression, I think a lot of people end up 
 putting code in the Controller when they first start using MVC (I did so 
 myself in the past).
 
 The Model should be external to your Catalyst app (or whatever framework you 
 use) so that you can use it in things like cron jobs. It also makes testing 
 easier if your Model is separate from your Catalyst app. Look at using 
 something like Catalyst::Model::Adaptor as a thin shell to add your external 
 Model into Catalyst.
 
 I am moving more and more into making my Controllers as thin as possible. 
 Logic that I might have previously put into the Controller, I either put into 
 the Model or I create helper functions. Here is an example of a Controller 
 (from Mojolicious as it happens but that is not important)
 
 sub user_list {
 my ($self) = @_;
 
 $self-jqgrid-render($self, {
 rs  = $self-schema-resultset('User')-search_rs,
 filters = {},
 rows= [qw(id name)],
 });
 }
 
 It's not important to know what is going on here, but this Controller gets a 
 list of all users, formats the data for use in the jQuery jqGrid allows for 
 sorting and filtering and outputs the data in JSON format. The point being, 
 the controller code is kept simple and 'thin'
 and yet it does a lot of work behind the scenes.
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/
 This Email and any attachments contain confidential information and is 
 intended solely for the individual to whom it is addressed. If this Email has 
 been misdirected, please notify the author as soon as possible. If you are 
 not the intended recipient you must not disclose, distribute, copy, print or 
 rely on any of the information contained, and all copies must be deleted 
 immediately. 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 
 viruses 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 
 HomeLoan Partn
 ership ha
s the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership

Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Lukas Thiemeier
Hi Craig,

You don't understand why $c-model('Model1') retrieves and data,
because it doesn't retrieve any data.

Database-code in the controller should be avoided, and instead be
implemented in the model.

My code just passes a reference to Model2 to Model1, so Model1 can
access data from Model2.

Within Model1, you can use prepare, execute, fetch et cetera on
Model1 and Model2, to fetch the data for your calculations.

Nevertheless, i think that your idea to create a extra model, which has
access to both underlying databases, is a better choice.

Lukas

On 10/30/2012 01:16 PM, Craig Chant wrote:
 Thanks Lukas,
 
 Chained method calls is not my strong point in Perl, they seem easier to read 
 in other languages with bracketed encapsulation and the dot notation.
 
 Your helper method is interesting, though I don't understand how 
 $c-model(Model1); retrieves any SQL data, like I said wrapping my head 
 around this is a bit of an uphill struggle currently.
 
 Regards,
 
 Craig.
 
 
 -Original Message-
 From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
 Sent: 30 October 2012 11:28
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] Why is $c undefined?
 
 Hi Craig,
 
 On 10/30/2012 12:09 PM, Craig Chant wrote:
 Thanks Ian,

 The hierarchy is something that I am finding mind-blowing at the moment,
 $self-jqgrid-render($self, , you are calling methods jqgrid-render on 
 $self, passing in $self, I'm sure it makes sense to you :-)

 
 No, he is calling render on whatever is returned by $self-jqgrid.
 Thats why $self has to be passed to render. The code above is equivalent to:
 
   my $jqgrid = $self-jqgrid;
   $jqgrid-render($self, ...);
 
 
 One thing I would like clarification with if possible.

 Where do I put code that requires the use of more than one model?

 Do I create a separate model that acts as an interface between the other 
 models?
 
 Thats one possibility. Another possibility would be to create a helper method 
 in Model1, which expects Model2 as a parameter.
 
 Model1.pm:
 
   sub calculate_sth_with_model2{
 my ($self, $model2) = @_;
 do_crazy_calculations();
   }
 
 And in your Controller:
 
   sub calculate :Local :Args(0) {
 my ($self, $c) = @_;
 
 my $m1 = $c-model(Model1);
 my $m2 = $c-model(Model2);
 
 $m1-calculate_sth_with_model2($m2);
 
   }
 

 You see I have two SQL servers in opposite ends of the country and so I have 
 a model built on Model::DBI that can access one server and another Model 
 that can access the other, but I have functionality that needs data from 
 both , do some calculations and output accordingly.

 I assume this does not go in the controller, but I create an interface model 
 with the required methods and functionality that the controller uses?

 Regards,

 Craig.

 -Original Message-
 From: Ian Docherty [mailto:catal...@iandocherty.com]
 Sent: 30 October 2012 07:22
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] Why is $c undefined?

 On 29 October 2012 21:01, Craig Chant cr...@homeloanpartnership.com wrote:
 ...

 I have read and seen frameworks such as Mojolicious encourage a shrinkage 
 of the Model and move alot of functionality to the Controller, so there is 
 a paradigm which seems to imply it is ok to do more stuff in the 
 Controller, but I am leaning towards having the main code in the Model and 
 then bolting it together via the Controller.

 I can understand why you get this impression, I think a lot of people end up 
 putting code in the Controller when they first start using MVC (I did so 
 myself in the past).

 The Model should be external to your Catalyst app (or whatever framework you 
 use) so that you can use it in things like cron jobs. It also makes testing 
 easier if your Model is separate from your Catalyst app. Look at using 
 something like Catalyst::Model::Adaptor as a thin shell to add your external 
 Model into Catalyst.

 I am moving more and more into making my Controllers as thin as
 possible. Logic that I might have previously put into the Controller,
 I either put into the Model or I create helper functions. Here is an
 example of a Controller (from Mojolicious as it happens but that is
 not important)

 sub user_list {
 my ($self) = @_;

 $self-jqgrid-render($self, {
 rs  = $self-schema-resultset('User')-search_rs,
 filters = {},
 rows= [qw(id name)],
 });
 }

 It's not important to know what is going on here, but this Controller gets a 
 list of all users, formats the data for use in the jQuery jqGrid allows for 
 sorting and filtering and outputs the data in JSON format. The point being, 
 the controller code is kept simple and 'thin'
 and yet it does a lot of work behind the scenes.

 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive:
 http://www.mail-archive.com

Re: [Catalyst] Why is $c undefined?

2012-10-29 Thread Rob Brown
There's no black-magic going on, so your AuthenticateUser() sub never 
magically gets $c.


In short, you'll only get $c when using the method attributes, such as 
:Private, :Chained, etc.





On 10/29/2012 07:07 PM, Craig Chant wrote:

Hi,

I seem to be unable to work out why $c is never automatically passed to
any of my models or methods?

I have in root.pm

# always runs first!

sub begin :Private {

my ( $self, $c ) = @_;

# Authenticate

$self-AuthenticateUser();

return 1;

}

I then have...

sub AuthenticateUser {

my ( $self, $c ) = @_;

$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?

Thanks,

Craig .

This Email and any attachments contain confidential information and is
intended solely for the individual to whom it is addressed. If this
Email has been misdirected, please notify the author as soon as
possible. If you are not the intended recipient you must not disclose,
distribute, copy, print or rely on any of the information contained, and
all copies must be deleted immediately. 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 viruses 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 HomeLoan 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.



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


--
IntelCompute
Web Design  Online Marketing Experts

http://www.intelcompute.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Why is $c undefined?

2012-10-29 Thread will trillich
On Mon, Oct 29, 2012 at 2:07 PM, Craig Chant
cr...@homeloanpartnership.comwrote:

  sub begin :Private {



 my ( $self, $c ) = @_;



 # Authenticate

 $self-AuthenticateUser();


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



  return 1;



 }



 I then have...



 sub AuthenticateUser {



 my ( $self, $c ) = @_;



 $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

“Grading takes away all the fun from failing. And a huge part of education
is about failure.”  -- Shimon Schocken
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Why is $c undefined?

2012-10-29 Thread Craig Chant
Cool, thanks.

Reading the tutorial I got the impression $c was always passed.

Thanks for clearing that up, which is why I guess $c-dbh doesn't exist.

hmm, much for me to get my head round for sure!

Regards,

Craig.


From: Rob Brown [r...@intelcompute.com]
Sent: 29 October 2012 19:11
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Why is $c undefined?

There's no black-magic going on, so your AuthenticateUser() sub never
magically gets $c.

In short, you'll only get $c when using the method attributes, such as
:Private, :Chained, etc.




On 10/29/2012 07:07 PM, Craig Chant wrote:
 Hi,

 I seem to be unable to work out why $c is never automatically passed to
 any of my models or methods?

 I have in root.pm

 # always runs first!

 sub begin :Private {

 my ( $self, $c ) = @_;

 # Authenticate

 $self-AuthenticateUser();

 return 1;

 }

 I then have...

 sub AuthenticateUser {

 my ( $self, $c ) = @_;

 $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?

 Thanks,

 Craig .

 This Email and any attachments contain confidential information and is
 intended solely for the individual to whom it is addressed. If this
 Email has been misdirected, please notify the author as soon as
 possible. If you are not the intended recipient you must not disclose,
 distribute, copy, print or rely on any of the information contained, and
 all copies must be deleted immediately. 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 viruses 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 HomeLoan 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.



 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/

--
IntelCompute
Web Design  Online Marketing Experts

http://www.intelcompute.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
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 viruses 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 HomeLoan 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.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http

Re: [Catalyst] Why is $c undefined?

2012-10-29 Thread Lukas Thiemeier
Hi again,

$c is automatically passed to Catalyst-actions  (not methods), but only
if you use Catalyst to do so.

If you call

 $self-someaction;

or

  $c-controller('SomeController')-someaction();

it is not passed. How can catalyst know if you are calling a catalyst
action, or any method on any object? And even if the object is a
catalyst controller, how can catalyst know if it is a action, which
requires the context, or just a helper, which doesn't use the context?

If you want catalyst to pass $c, use $c-forward, $c-detach, $c-visit
and $c-go instead:

  $c-forward(/someaction);

or

  $c-forward($c-controller('MyController')-action_for(someaction));

or

  $c-forward(/somecontroller/someaction);

Read the main catalyst docs for details. (perldoc Catalyst)

Lukas

On 10/29/2012 08:07 PM, Craig Chant wrote:
 Hi,
 
  
 
 I seem to be unable to work out why $c is never automatically passed to
 any of my models or methods?
 
  
 
 I have in root.pm
 
  
 
 # always runs first!
 
 sub begin :Private {
 

 
 my ( $self, $c ) = @_;
 
  
 
 # Authenticate
 
 $self-AuthenticateUser();   
 
 return 1;
 

 
 }
 
  
 
 I then have...
 
  
 
 sub AuthenticateUser {
 

 
 my ( $self, $c ) = @_;   
 
 
 
 $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?
 
  
 
 Thanks,
 
  
 
 Craig .
 
 This Email and any attachments contain confidential information and is
 intended solely for the individual to whom it is addressed. If this
 Email has been misdirected, please notify the author as soon as
 possible. If you are not the intended recipient you must not disclose,
 distribute, copy, print or rely on any of the information contained, and
 all copies must be deleted immediately. 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 viruses 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 HomeLoan 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.
 
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Why is $c undefined?

2012-10-29 Thread Craig Chant
Thanks Will,



Appreciate you clarifying this for me.



CRaig.


From: will trillich [will.trill...@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 
cr...@homeloanpartnership.commailto:cr...@homeloanpartnership.com wrote:
sub begin :Private {

my ( $self, $c ) = @_;

# Authenticate
$self-AuthenticateUser();

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


return 1;

}

I then have...

sub AuthenticateUser {

my ( $self, $c ) = @_;

$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.


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

“Grading takes away all the fun from failing. And a huge part of education is 
about failure.”  -- Shimon Schocken
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
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 viruses 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 HomeLoan 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.
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Why is $c undefined?

2012-10-29 Thread Rob Brown

Just a small FYI more than anything, which might help fill in a few gaps...

$c-dbh would need you to modify MyApp.pm, this is useful at times for 
creating little helper methods that you want accessible via $c, or to 
override existing $c methods.


The session plugin does this too, that's why $c-sessionid is available, 
etc. or $c-check_user_roles() when using the Authorization::Roles plugin.


I'm not sure you'd really want $c-dbh anyway, since that's doesn't 
sound like you would be encapsulating the Model very well, and sounds 
like you'd have SQL in your controller code?




On 10/29/2012 07:28 PM, Craig Chant wrote:

Cool, thanks.

Reading the tutorial I got the impression $c was always passed.

Thanks for clearing that up, which is why I guess $c-dbh doesn't exist.

hmm, much for me to get my head round for sure!

Regards,

Craig.


From: Rob Brown [r...@intelcompute.com]
Sent: 29 October 2012 19:11
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Why is $c undefined?

There's no black-magic going on, so your AuthenticateUser() sub never
magically gets $c.

In short, you'll only get $c when using the method attributes, such as
:Private, :Chained, etc.




On 10/29/2012 07:07 PM, Craig Chant wrote:

Hi,

I seem to be unable to work out why $c is never automatically passed to
any of my models or methods?

I have in root.pm

# always runs first!

sub begin :Private {

my ( $self, $c ) = @_;

# Authenticate

$self-AuthenticateUser();

return 1;

}

I then have...

sub AuthenticateUser {

my ( $self, $c ) = @_;

$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?

Thanks,

Craig .

This Email and any attachments contain confidential information and is
intended solely for the individual to whom it is addressed. If this
Email has been misdirected, please notify the author as soon as
possible. If you are not the intended recipient you must not disclose,
distribute, copy, print or rely on any of the information contained, and
all copies must be deleted immediately. 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 viruses 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 HomeLoan 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.



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


--
IntelCompute
Web Design  Online Marketing Experts

http://www.intelcompute.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
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 viruses 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 HomeLoan Partn

ership has the authority to enter into any

RE: [Catalyst] Why is $c undefined?

2012-10-29 Thread Craig Chant
I'm not sure you'd really want $c-dbh anyway, since that's doesn't
sound like you would be encapsulating the Model very well, and sounds
like you'd have SQL in your controller code?

This was what I thought and am trying to avoid, I am doing my best to keep 
concern with SQL trot he Model and any action/method that requires data to use 
the Model and have the business logic kept in the Model, so that only 
actions-routes and the additional application helper methods are in the 
controller.

I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
the Model and move alot of functionality to the Controller, so there is a 
paradigm which seems to imply it is ok to do more stuff in the Controller, but 
I am leaning towards having the main code in the Model and then bolting it 
together via the Controller.

So for example the authentication for the user is in the Controller but it 
simply utilises the Model

EG.

sub AuthenticateUser {

my ( $self, $c ) = @_;

$c-session;
if(!$c-model('Members')-LogCheck($c)){
$c-forward('/login/login');
}

}

Dunno, this is all new to me and I'm refactoring as I go, so I doubt I'll get 
it right first time! Does anyone?



From: Rob Brown [r...@intelcompute.com]
Sent: 29 October 2012 19:39
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Why is $c undefined?

Just a small FYI more than anything, which might help fill in a few gaps...

$c-dbh would need you to modify MyApp.pm, this is useful at times for
creating little helper methods that you want accessible via $c, or to
override existing $c methods.

The session plugin does this too, that's why $c-sessionid is available,
etc. or $c-check_user_roles() when using the Authorization::Roles plugin.

I'm not sure you'd really want $c-dbh anyway, since that's doesn't
sound like you would be encapsulating the Model very well, and sounds
like you'd have SQL in your controller code?



On 10/29/2012 07:28 PM, Craig Chant wrote:
 Cool, thanks.

 Reading the tutorial I got the impression $c was always passed.

 Thanks for clearing that up, which is why I guess $c-dbh doesn't exist.

 hmm, much for me to get my head round for sure!

 Regards,

 Craig.

 
 From: Rob Brown [r...@intelcompute.com]
 Sent: 29 October 2012 19:11
 To: catalyst@lists.scsys.co.uk
 Subject: Re: [Catalyst] Why is $c undefined?

 There's no black-magic going on, so your AuthenticateUser() sub never
 magically gets $c.

 In short, you'll only get $c when using the method attributes, such as
 :Private, :Chained, etc.




 On 10/29/2012 07:07 PM, Craig Chant wrote:
 Hi,

 I seem to be unable to work out why $c is never automatically passed to
 any of my models or methods?

 I have in root.pm

 # always runs first!

 sub begin :Private {

 my ( $self, $c ) = @_;

 # Authenticate

 $self-AuthenticateUser();

 return 1;

 }

 I then have...

 sub AuthenticateUser {

 my ( $self, $c ) = @_;

 $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?

 Thanks,

 Craig .

 This Email and any attachments contain confidential information and is
 intended solely for the individual to whom it is addressed. If this
 Email has been misdirected, please notify the author as soon as
 possible. If you are not the intended recipient you must not disclose,
 distribute, copy, print or rely on any of the information contained, and
 all copies must be deleted immediately. 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 viruses 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 HomeLoan 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.



 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst