File Coverage

blib/lib/Mojolicious/Plugin/Debugbar.pm
Criterion Covered Total %
statement 6 20 30.0
branch 0 4 0.0
condition n/a
subroutine 2 5 40.0
pod 1 1 100.0
total 9 30 30.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Debugbar;
2 2     2   407389 use Mojo::Base 'Mojolicious::Plugin';
  2         28073  
  2         15  
3              
4 2     2   4274 use Mojo::Debugbar;
  2         558793  
  2         13  
5              
6             our $VERSION = '0.1.2';
7              
8             =head2 register
9              
10             =cut
11              
12             sub register {
13 0     0 1   my ($self, $app, $config) = @_;
14              
15 0           my $debugbar = Mojo::Debugbar->new(app => $app, config => $config);
16              
17             $app->hook(around_dispatch => sub {
18 0     0     my ($next, $c) = @_;
19              
20             # Start recording
21 0           $debugbar->start;
22              
23 0           $next->();
24              
25             # Stop recording
26 0           $debugbar->stop;
27 0           });
28              
29             $app->hook(after_render => sub {
30 0     0     my ($c, $output, $format) = @_;
31              
32 0 0         return unless $format eq 'html';
33              
34             # if there is a tag, inject the debugbar
35 0 0         if ($$output =~ m/<\/body>/) {
36             # Render the debugbar html
37 0           my $html = $debugbar->render;
38              
39             # Append text before the closing tag
40 0           $$output =~ s!()!$html$1!;
41             } else {
42             # Append text at the end of the output
43 0           $$output .= $debugbar->inject;
44             }
45 0           });
46             }
47              
48             1;