| 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 | 7 | use Mojo::Base -base; | |||
| 1 | 3 | ||||||
| 1 | 8 | ||||||
| 3 | |||||||
| 4 | 1 | 1 | 153 | use Mojo::Util qw(md5_sum); | |||
| 1 | 2 | ||||||
| 1 | 91 | ||||||
| 5 | 1 | 1 | 6 | use Time::HiRes qw(time); | |||
| 1 | 3 | ||||||
| 1 | 8 | ||||||
| 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(' |
|||||
| 116 | '%s %s (%s)' + | ||||||
| 117 | '', $id, $monitor->icon, $monitor->name, $count); | ||||||
| 118 | |||||||
| 119 | 0 | $content .= sprintf(' %s ', $id, $monitor->render); |
|||||
| 120 | } | ||||||
| 121 | |||||||
| 122 | 0 | return sprintf( | |||||
| 123 | '%s | ||||||
| 124 | |||||||
| 125 | |
||||||
| 126 | |||||||
| 127 | |||||||
| 128 | |||||||
| 129 | |||||||
| 130 | |||||||
| 131 | |||||||
| 132 | |||||||
| 133 | |||||||
| 134 | |||||||
| 135 | |||||||
| 136 | |||||||
| 137 | |||||||
| 138 | %s |
||||||
| 139 | |||||||
| 140 | |||||||
| 141 | %s', | ||||||
| 142 | $self->css, $tabs, $self->duration, $content, $self->javascript | ||||||
| 143 | ); | ||||||
| 144 | } | ||||||
| 145 | |||||||
| 146 | =head2 stop | ||||||
| 147 | Loops through each monitor and calls stop then stops the timer | ||||||
| 148 | =cut | ||||||
| 149 | |||||||
| 150 | sub stop { | ||||||
| 151 | 0 | 0 | 1 | my $self = shift; | |||
| 152 | |||||||
| 153 | 0 | $_->stop for @{ $self->registered }; | |||||
| 0 | |||||||
| 154 | |||||||
| 155 | 0 | $self->ended_at(time()); | |||||
| 156 | } | ||||||
| 157 | |||||||
| 158 | =head2 start | ||||||
| 159 | Starts the timer and loops through each monitor and calls start | ||||||
| 160 | =cut | ||||||
| 161 | |||||||
| 162 | sub start { | ||||||
| 163 | 0 | 0 | 1 | my $self = shift; | |||
| 164 | |||||||
| 165 | 0 | $self->started_at(time()); | |||||
| 166 | |||||||
| 167 | 0 | $_->start for @{ $self->registered }; | |||||
| 0 | |||||||
| 168 | } | ||||||
| 169 | |||||||
| 170 | 1; |