| 1 | package Plack::Middleware::Debug::Dancer::TemplateVariables; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 1 | $Plack::Middleware::Debug::Dancer::TemplateVariables::VERSION = '0.002'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | # ABSTRACT: Debug and inspect your template variables for Dancer | ||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use parent qw(Plack::Middleware::Debug::Base); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use Dancer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Data::Dumper (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 1 | my $env_key = 'debug.dancer.templatevariables'; | |||||||||||
| 15 | |||||||||||||
| 16 | 0 | ▶ | sub prepare_app { | ||||||||||
|
Subroutine
prepare_app: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 17 | 0 | ▶ | Dancer::Hook->new('before_layout_render' => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 18 | 0 | my $tokens = shift; | |||||||||||
| 19 | 0 | Dancer::SharedData->request->env->{$env_key} = $tokens; | |||||||||||
| 20 | 0 | }); | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 1 | my $list_template_dumped = __PACKAGE__->build_template(<<'EOTMPL'); | |||||||||||
| 24 | <table> | ||||||||||||
| 25 | <thead> | ||||||||||||
| 26 | <tr> | ||||||||||||
| 27 | <th>Key</th> | ||||||||||||
| 28 | <th>Value</th> | ||||||||||||
| 29 | </tr> | ||||||||||||
| 30 | </thead> | ||||||||||||
| 31 | <tbody> | ||||||||||||
| 32 | % my $i; | ||||||||||||
| 33 | % while (@{$_[0]->{list}}) { | ||||||||||||
| 34 | % my($key, $value) = splice(@{$_[0]->{list}}, 0, 2); | ||||||||||||
| 35 | <tr class="<%= ++$i % 2 ? 'plDebugOdd' : 'plDebugEven' %>"> | ||||||||||||
| 36 | <td><%= $key %></td> | ||||||||||||
| 37 | <td><pre><%= vardump($value) %></pre></td> | ||||||||||||
| 38 | </tr> | ||||||||||||
| 39 | % } | ||||||||||||
| 40 | </tbody> | ||||||||||||
| 41 | </table> | ||||||||||||
| 42 | EOTMPL | ||||||||||||
| 43 | |||||||||||||
| 44 | 0 | ▶ | sub vardump { | ||||||||||
|
Subroutine
vardump: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 45 | 0 | my $scalar = shift; | |||||||||||
| 46 | 0 | ▶ | return '(undef)' unless defined $scalar; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | ▶ | return "$scalar" unless ref $scalar; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | scalar Data::Dump::dump($scalar); | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub run { | ||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 52 | 0 | my ( $self, $env, $panel ) = @_; | |||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | return sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 55 | 0 | my $res = shift; | |||||||||||
| 56 | 0 | $panel->title('Dancer::TemplateVariables'); | |||||||||||
| 57 | 0 | $panel->nav_subtitle('Dancer::TemplateVariables'); | |||||||||||
| 58 | 0 | ▶ | $panel->content( sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 59 | 0 | ▶ | my %vars = %{ $env->{$env_key} || {} }; | ||||||||||
|
Condition0%0/2
$env->{$env_key} || {}
MC/DC0%0/1
$env->{$env_key} || {}
$env->{$env_key}
Truth table0%0/2
A
A= $env->{$env_key}
| |||||||||||||
| 60 | 0 | my @var_list = map { $_ => $vars{$_} } sort keys %vars; | |||||||||||
| 61 | 0 | $self->render( $list_template_dumped, { list => \@var_list } ); | |||||||||||
| 62 | 0 | } ); | |||||||||||
| 63 | 0 | }; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | 1; | |||||||||||
| 67 | |||||||||||||
| 68 | |||||||||||||
| 69 | __END__ | ||||||||||||