Skip to content

Commit

Permalink
added MOJO_TEMPLATE_DEBUG environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 12, 2012
1 parent 35ff80a commit 815d10c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mojo/Base.pm
Expand Up @@ -95,7 +95,7 @@ sub attr {
no strict 'refs';
no warnings 'redefine';
*{"${class}::$attr"} = eval $code or Carp::croak("Mojo::Base error: $@");
warn "\nATTRIBUTE: $class->$attr\n$code\n\n" if $ENV{MOJO_BASE_DEBUG};
warn "-- Attribute ($class->$attr)\n$code\n\n" if $ENV{MOJO_BASE_DEBUG};
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/Mojo/Template.pm
Expand Up @@ -6,6 +6,8 @@ use Mojo::ByteStream;
use Mojo::Exception;
use Mojo::Util qw(decode encode slurp);

use constant DEBUG => $ENV{MOJO_TEMPLATE_DEBUG} || 0;

# "If for any reason you're not completely satisfied, I hate you."
has [qw(auto_escape compiled)];
has [qw(append code prepend template)] => '';
Expand Down Expand Up @@ -109,6 +111,7 @@ sub build {
$lines[0] = 'package ' . $self->namespace . "; $HELPERS ";
$lines[0] .= "sub { my \$_M = ''; " . $self->prepend . "; do { $first";
$lines[-1] .= $self->append . "; \$_M; } };";
warn "-- Compiled (@{[$self->name]})\n", join("\n", @lines), "\n\n" if DEBUG;

return $self->code(join "\n", @lines)->tree([]);
}
Expand Down Expand Up @@ -679,6 +682,13 @@ Render template.
Render template file.
=head1 DEBUGGING
You can set the C<MOJO_TEMPLATE_DEBUG> environment variable to get some
advanced diagnostics information printed to C<STDERR>.
MOJO_TEMPLATE_DEBUG=1
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down

0 comments on commit 815d10c

Please sign in to comment.