[Dbix-class] How to set debugobj in DBIC

Jason Kohles email at jasonkohles.com
Sat Mar 17 19:50:43 GMT 2007


On Mar 17, 2007, at 11:48 AM, RA Jones wrote:

> RA Jones wrote:
>
>> Trying various places to set debugobj so far has failed with error  
>> messages, usually relating to storage. In reality I've no idea  
>> where to start with this. The intuitive place to set the debugobj  
>> is either MyApp/lib/Schema.pm or MyApp::Model::Schema.pm, but  
>> neither seems to work. Presumably I shouldn't be doing this in the  
>> MyApp/lib/Schema DBIC classes? A simple code example is really all  
>> I need to get going.
>
> I'm still getting nowhere with this, and also found a reference on  
> the internet to a similar problem with the Profiling section of the  
> DBIx::Class::Manual::Cookbook. The OP did not get a definitive  
> answer. Is it actually possible to set the debugobj, or is it urban  
> myth?
>
> My attempts so far:
>
> use My::MySQL::Profiler;
> __PACKAGE__->storage()->debugobj(new My::MySQL::Profiler());
> __PACKAGE__->storage()->debug(1);
>

If you haven't instantiated your schema, then storage doesn't contain  
anything:

use MyDB::Schema;

my $schema = MyDB::Schema->connection( 'DBI:MySQL:dbname=foo' );
$schema->storage->debugobj( My::MySQL::Profiler->new() );
$schema->storage->debug( 1 );
# ... do other stuff ...

> 3) In root controller MyApp::Controller::Root:
> Can't locate object method "storage" via package  
> "MyApp::Controller::Root" at /home/www/apps/MyApp/script/../lib/ 
> MyApp/Controller/Root.pm line 16.
> Compilation failed in require at (eval 171) line 3.
> Compilation failed in require at script/myapp_server.pl line 53.
>
> What am I doing wrong?

I haven't tried this, but if you are trying to do it in Catalyst,  
your best bet is probably to inject it into the model...

package MyApp::Model::MyDB;
use strict;
use warnings;
use base 'Catalyst::Model::DBIC::Schema';
use NEXT;

__PACKAGE__->config( schema_class => 'MyDB::Schema' );

sub new {
     my $self = shift->NEXT::new( @_ );
     $self->storage->debugobj( My::MySQL::Profiler->new() );
     $self->storage->debug( 1 );
     return $self;
}

-- 
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire





More information about the Dbix-class mailing list