[Catalyst] Catalyst::Plugin::DBIC::QueryLog
Guillermo Roditi
groditi at gmail.com
Sat Sep 1 13:58:43 GMT 2007
I want this too
On 9/1/07, Marcus Ramberg <marcus.ramberg at gmail.com> wrote:
>
> I don't know DBIx::Class::QueryLog, but as a catalyst plugin it looks
> fine. Write some tests and ship it to cpan, I want this ;)
>
> Marcus Ramberg
>
> On 9/1/07, Fayland Lam <fayland at gmail.com> wrote:
> > hi, guys.
> >
> > since I can't touch Cory Watson by gphat at cpan.org <mailto:gphat at cpan.org
> >
> > so I wonder if this module is fine?
> >
> > Thanks.
> > <mailto:gphat at cpan.org>
> >
> > --
> > Fayland Lam // http://www.fayland.org/
> >
> >
> > package Catalyst::Plugin::DBIC::QueryLog;
> >
> > use warnings;
> > use strict;
> >
> > use NEXT;
> > use DBIx::Class::QueryLog;
> > use DBIx::Class::QueryLog::Analyzer;
> >
> > use base qw/Class::Accessor::Fast/;
> > __PACKAGE__->mk_accessors('querylog');
> >
> > use vars qw/$VERSION/;
> > $VERSION =3D '0.01';
> >
> > sub querylog_analyzer {
> > my $c =3D shift;
> >
> > return new DBIx::Class::QueryLog::Analyzer({ querylog =3D>
> $c->querylog });
> > }
> >
> > sub prepare {
> > my $c =3D shift;
> > $c =3D $c->NEXT::prepare(@_);
> >
> > my $model_name =3D $c->config->{'DBIC::QueryLog'}->{MODEL_NAME} ||
> 'DBIC';
> >
> > my $schema =3D $c->model($model_name)->schema;
> > $c->querylog( new DBIx::Class::QueryLog() );
> > $schema->storage->debugobj( $c->querylog );
> > $schema->storage->debug(1);
> >
> > return $c;
> > }
> >
> > 1; # End of Catalyst::Plugin::DBIC::QueryLog
> > __END__
> >
> > =3Dhead1 NAME
> >
> > Catalyst::Plugin::DBIC::QueryLog - Catalyst Plugin for
> DBIx::Class::QueryLog!
> >
> > =3Dhead1 SYNOPSIS
> >
> > # MyApp.pm
> > use Catalyst qw/
> > ...
> > DBIC::QueryLog # Load this plugin.
> > ...
> > /;
> >
> > # myapp.yml
> > DBIC::QueryLog:
> > MODEL_NAME: DBIC
> >
> > =3Dhead1 USAGE
> >
> > then in templates:
> >
> > [% IF c.querylog %]
> > <div class=3D"featurebox">
> > <h3>Query Log Report</h3>
> > [% SET total =3D c.querylog.time_elapsed | format('%0.6f') %]
> > <div>Total SQL Time: [% total | format('%0.6f') %] seconds</div>
> > [% SET qcount =3D c.querylog.count %]
> > <div>Total Queries: [% qcount %]</div>
> > [% IF qcount %]
> > <div>Avg Statement Time: [% (c.querylog.time_elapsed / qcount) |
> format('%0.6f') %] seconds.</div>
> > <div>
> > <table class=3D"table1">
> > <thead>
> > <tr>
> > <th colspan=3D"3">5 Slowest Queries</th>
> > </tr>
> > </thead>
> > <tbody>
> > <tr>
> > <th>Time</th>
> > <th>%</th>
> > <th>SQL</th>
> > </tr>
> > [% SET i =3D 0 %]
> > [% FOREACH q =3D c.querylog_analyzer.get_sorted_queries %]
> > <tr class=3D"[% IF loop.count % 2 %]odd[% END %]">
> > <th class=3D"sub">[% q.time_elapsed | format('%0.6f') %]
> > <td>[% ((q.time_elapsed / total ) * 100 ) | format('%i')
> %]%</td>
> > <td>[% q.sql %]</td>
> > </th></tr>
> > [% IF i =3D=3D 5 %]
> > [% LAST %]
> > [% END %]
> > [% SET i =3D i + 1 %]
> > [% END %]
> > </tbody>
> > </table>
> > </div>
> > [% END %]
> > </div>
> > [% END %]
> >
> > =3Dhead1 SEE ALSO
> >
> > L<DBIx::Class::QueryLog>
> >
> > L<
> http://www.onemogin.com/blog/554-profile-your-catalystdbixclass-app-with-=
querylog.html
> >
> >
> > =3Dhead1 AUTHOR
> >
> > Fayland Lam, C<< <fayland at gmail> >>
> >
> > =3Dhead1 COPYRIGHT & LICENSE
> >
> > Copyright 2007 Fayland Lam, all rights reserved.
> >
> > This program is free software; you can redistribute it and/or modify it
> > under the same terms as Perl itself.
> >
> > =3Dcut
> >
> > _______________________________________________
> > List: Catalyst at lists.rawmode.org
> > Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> > Searchable archive:
> http://www.mail-archive.com/catalyst@lists.rawmode.org/
> > Dev site: http://dev.catalyst.perl.org/
> >
> >
>
>
> --
> With regards
> Marcus Ramberg
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070901/96221=
1d5/attachment.htm
More information about the Catalyst
mailing list