[Dbix-class] Retrieving list of loaded modules in MyApp::Model::Schema

Jess Robinson castaway at desert-island.me.uk
Mon Mar 26 09:50:36 GMT 2007



On Thu, 22 Mar 2007, RA Jones wrote:

> Following on from another thread about how to handle the debugobj, I've run 
> into another conundrum. In trying out various SQL profiling configurations, I 
> selectively load or comment out the base modules in MyApp.pm:
>
> use Catalyst qw(lots of modules);
>
> In doing so I can test for their existence in the controllers:
>
> if ( $c->registered_plugins('DBIx::Class::QueryLog') ) {
> do_something_with_DBIC-QueryLog
> }
>
> But how can I do the equivalent in the Model/Schema class, which does not 
> know anything about $c. I want to do something like:
>
> use base 'Catalyst::Model::DBIC::Schema';
>
> sub new {
>   my $self = shift->NEXT::new( @_ );
>
>      if ( module_x is loaded ) { setup storage on x }
>   elsif ( module_y is loaded ) { setup storage on y }
>
>  return $self;
> }
>

I was about to suggest you read the docs of DBIx::Class::Componentised.. 
Then I realised it doesn't have any.. Regardless, it has an 
"ensure_class_found" method, which may do what you want. Try looking at 
the code.

Also most components in DBIx::Class are stuffed into the base of the 
ResultSources, so you can just check isa() for those.

Jess



More information about the Dbix-class mailing list