[Catalyst] Accessing $self in a plugin?

2009-12-23 Thread Octavian Râşniţă

Hi,

I use Catalyst::Controller::HTML::FormFu but in some actions I don't want to 
use the FormConfig attribute because it would automaticly generate and 
process a form, which takes much time. I want to do that only if the already 
generated template and data was not found in the cache.


But instead of writing each time

my $form = $self-form;
$form-load_config_filestem('path/to/config_file');
$form-process;
$c-stash-{form} = $form;

I would prefer to write a plugin, and write only something like:

$c-ff('path/to/config_file');

First, is this correct? (or it might appear some issues). I know that the 
plugins are not recommended, but it is not a Catalyst plugin for public use, 
but only one for my app.


And if it is ok, is it possible to get $self in the plugin in order to do 
$self-form?


Or I will need to send it explicitly using:

$ff($self, 'path/to/config_file');

Thanks.

Octavian


___
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] Accessing $self in a plugin?

2009-12-23 Thread Andrew Rodland
On Wednesday 23 December 2009 03:40:37 am Octavian Râşniţă wrote:
 Hi,
 
 I use Catalyst::Controller::HTML::FormFu but in some actions I don't want
  to use the FormConfig attribute because it would automaticly generate and
  process a form, which takes much time. I want to do that only if the
  already generated template and data was not found in the cache.
 [...]

  First, is this correct? (or it might appear some issues). I know that the
 plugins are not recommended, but it is not a Catalyst plugin for public
  use, but only one for my app.

Maybe you should extend C::C::HTML::FormFu to have the caching behavior you 
want, and then just use *that* as a controller base class?


 And if it is ok, is it possible to get $self in the plugin in order to do
 $self-form?
 
 Or I will need to send it explicitly using:
 
 $ff($self, 'path/to/config_file');
 

When running an action, the '$self' is the Controller. Outside of the action, 
you can get the controller for the dispatched action with $c-controller() (no 
argument).

Andrew

___
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/