tokuhirom's blog

How can I deny a DB access in a view?

Here is an example code. DBIx::Tracer can hook the DB access in a lexical context.

package MyApp::Web;
use DBIx::Tracer;

sub render {
    my ($c, $tmpl, $vars) = @_;
    my $tracer = $ENV{IN_DEBUGGING} ? DBIx::Tracer->new(
        sub {
            my %args = @_;
            my $sql = $args{sql};
            die "Do not execute query in a view: $sql";
    ) : undef;
    return $c->SUPER::render($tmpl, $vars);

Why do I need to deny it?

  • Designer can execute a lot of queries.
  • It makes debugging hard.
  • It makes NYTProf hard.
Created: 2012-11-09 10:20:10 UTC
Updated: 2012-11-09 10:20:10 UTC