[Catalyst] Usage of Catalyst::Plugin::Singleton

Alex Kavanagh alex at tinwood.homelinux.org
Mon Jan 23 21:30:41 CET 2006


Hi

I'm trying to work out the best way to get at the $c from various
parts of the application.

e.g. When using Data::FormValidator I want to be able to call various
functions in the model to check things like duplicated usernames, etc.

At the moment I'm playing with a class scope global and localising it
just before calling $c->form :

  local $__dbic = $c->model('SiteDBIC');
  my $res = $c->form( $self->_dfv->{ 'user_add_confirm' } );

Yuck!

Anyway, I spotted C:P:Singleton and it seems to allow access to the $c
via

my $c = Site->context;

May I ask:

1. What was the design decision behind not having a 'global' application
   object that you could just access?  Is it a threading issue, or
   something else?  i.e. the Singleton would effectively be breaking
   that design decision.

2. Rightly or wrongly (probably wrongly) I'm calling functions in
   other table classes in the DBIC model and I find I need to do this:

$c->model('ModelClass')->table('some other table')->function(params)

   but I don't have a $c unless I pass it around all over the place.
   So I wrote some nasty code in the model base class to inject a
   function called __dbic into the model table classes that simple
   return the model base class.  Thus I can do

   __dbic->table('some other table')->function(params)

Is this crappy design on my part?

Thanks for any guidance.

Cheers
Alex.



More information about the Catalyst mailing list