[Dbix-class] using DBIx::Class::Storage::Statistics per the Cookbook
Nathan Kurz
nate at verse.com
Sat Aug 12 23:19:05 CEST 2006
On Fri, Aug 11, 2006 at 03:31:33PM +0100, Richard Jolly wrote:
> dbix-class-bounces at lists.rawmode.org wrote:
> > I'm trying to get some query statistics using the methods
> > suggested in DBIx::Class::Manual::Cookbook, but I haven't had
> > any success yet.
> > When I try adding the lines:
> >
> > __PACKAGE__->storage()->debugobj(new My::Profiler());
> > __PACKAGE__->storage()->debug(1);
> >
> > to my schema class file, Catalyst refuses to start with the message:
> >
> > "Can't call method "debugobj" on an undefined value"
>
> [snip]
>
> Did you get a solution to this? I'd like to do the same thing.
Yes, I came up with a solution that seems to work. You need to set
the debugobj after the storage object is created, which in Catalyst
can be done by subclassing "Catalyst::::Model::DBIC::Schema" and
changing the operation of new() to set the debugobj.
----------------------------------------------------------------------
package App::Model::DB;
use strict;
use base 'Catalyst::Model::DBIC::Schema';
sub new {
my $class = shift;
my ($context, $config) = @_;
my $database = $config->{database};
my $user = '';
my $password = '';
my $options = {
AutoCommit => 1,
};
$class->config(
schema_class => 'App::Model::Schema',
connect_info => [$database, $user,
$password, $options],
);
my $self = $class->NEXT::new(@_);
use App::Model::Debug;
my $debug = new App::Model::Debug;
$self->storage->debugobj($debug);
# NOTE: to use set DBIC_TRACE=1 or add '$self->storage->debug(1);'
return $self;
}
__PACKAGE__;
--------------------------------------------------------------
Hope this helps,
Nathan Kurz
nate at verse.com
More information about the Dbix-class
mailing list