File Coverage

blib/lib/Mojo/Debugbar/Monitors.pm
Criterion Covered Total %
statement 9 30 30.0
branch 0 2 0.0
condition 0 3 0.0
subroutine 3 7 42.8
pod 4 4 100.0
total 16 46 34.7


line stmt bran cond sub pod time code
1             package Mojo::Debugbar::Monitors;
2 1     1   6 use Mojo::Base -base;
  1         2  
  1         5  
3              
4 1     1   117 use Mojo::Util qw(md5_sum);
  1         2  
  1         67  
5 1     1   6 use Time::HiRes qw(time);
  1         1  
  1         6  
6              
7             has 'css' => <<'EOF'
8            
61             EOF
62             ;
63             has 'javascript' => <<'EOF'
64            
81             EOF
82             ;
83             has 'registered' => sub { [] };
84             has 'hide_empty' => 0;
85             has 'started_at' => sub { time() };
86             has 'ended_at' => sub { time() };
87              
88             =head2 duration
89             Ended at - started at
90             =cut
91              
92             sub duration {
93 0     0 1   my $self = shift;
94              
95 0           return sprintf("%.4f", $self->ended_at - $self->started_at);
96             }
97              
98             =head2 render
99             Loops through each monitor and renders the html
100             =cut
101              
102             sub render {
103 0     0 1   my $self = shift;
104              
105 0           my $tabs = '';
106 0           my $content = '';
107              
108 0           foreach my $monitor (@{ $self->registered }) {
  0            
109 0           my $count = $monitor->count;
110              
111 0 0 0       next if ($self->hide_empty && !$count);
112              
113 0           my $id = md5_sum(ref($monitor));
114              
115 0           $tabs .= sprintf('
  • %s %s (%s)
  • ', $id, $monitor->icon, $monitor->name, $count);
    116            
    117 0           $content .= sprintf('
    %s
    ', $id, $monitor->render);
    118             }
    119              
    120 0           return sprintf(
    121             '%s
    122            
    123            
    124            
    125            
    126            
    127            
    128            
    129            
    130            
    131            
    132            
    133            
    134            
    135            
    136            
    %s
    137            
    138            
    139             %s',
    140             $self->css, $tabs, $self->duration, $content, $self->javascript
    141             );
    142             }
    143              
    144             =head2 stop
    145             Loops through each monitor and calls stop then stops the timer
    146             =cut
    147              
    148             sub stop {
    149 0     0 1   my $self = shift;
    150              
    151 0           $_->stop for @{ $self->registered };
      0            
    152              
    153 0           $self->ended_at(time());
    154             }
    155              
    156             =head2 start
    157             Starts the timer and loops through each monitor and calls start
    158             =cut
    159              
    160             sub start {
    161 0     0 1   my $self = shift;
    162              
    163 0           $self->started_at(time());
    164              
    165 0           $_->start for @{ $self->registered };
      0            
    166             }
    167              
    168             1;