On Fri, Aug 11, 2006 at 03:31:33PM +0100, Richard Jolly wrote:
> [EMAIL PROTECTED] 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
[EMAIL PROTECTED]

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/

Reply via email to