| 1 | package Mojo::Debugbar::Monitors; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Mojo::Util qw(md5_sum); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | has 'css' => <<'EOF' | |||||||||||||||||||||||||||
| 8 | <style type="text/css"> | ||||||||||||||||||||||||||||
| 9 | #debugbar-push { | ||||||||||||||||||||||||||||
| 10 | height: 39px; | ||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | #debugbar { | ||||||||||||||||||||||||||||
| 13 | position: fixed; | ||||||||||||||||||||||||||||
| 14 | right: 0; | ||||||||||||||||||||||||||||
| 15 | bottom: 0; | ||||||||||||||||||||||||||||
| 16 | left: 0; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | z-index: 1005; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | background-color: #fff; | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | #debugbar .debugbar-header { | ||||||||||||||||||||||||||||
| 23 | background-color: #f5f5f5; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | #debugbar .debugbar-header .debugbar-brand { | ||||||||||||||||||||||||||||
| 26 | position: absolute; | ||||||||||||||||||||||||||||
| 27 | top: 0; | ||||||||||||||||||||||||||||
| 28 | padding: 9px; | ||||||||||||||||||||||||||||
| 29 | border-right: 1px solid #ddd; | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | #debugbar .debugbar-header .nav-tabs { | ||||||||||||||||||||||||||||
| 32 | margin-left: 45px; | ||||||||||||||||||||||||||||
| 33 | margin-bottom: 0; | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | #debugbar .debugbar-header .nav-tabs .active a { | ||||||||||||||||||||||||||||
| 36 | color: #fff; | ||||||||||||||||||||||||||||
| 37 | background-color: #f4645f; | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | #debugbar .debugbar-header .debugbar-actions { | ||||||||||||||||||||||||||||
| 40 | position: absolute; | ||||||||||||||||||||||||||||
| 41 | top: 10px; | ||||||||||||||||||||||||||||
| 42 | right: 15px; | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | #debugbar .debugbar-header .debugbar-actions .minimize-debugbar { | ||||||||||||||||||||||||||||
| 45 | display: none; | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | #debugbar .debugbar-content { | ||||||||||||||||||||||||||||
| 48 | display: none; | ||||||||||||||||||||||||||||
| 49 | padding: 0 5px; | ||||||||||||||||||||||||||||
| 50 | height: 250px; | ||||||||||||||||||||||||||||
| 51 | overflow-y: auto; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | #debugbar-push.open { | ||||||||||||||||||||||||||||
| 54 | height: 289px; | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | #debugbar.open .debugbar-content { | ||||||||||||||||||||||||||||
| 57 | display: block; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | #debugbar.open .debugbar-header .debugbar-actions .minimize-debugbar { | ||||||||||||||||||||||||||||
| 60 | display: inline; | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | </style> | ||||||||||||||||||||||||||||
| 63 | EOF | ||||||||||||||||||||||||||||
| 64 | ; | ||||||||||||||||||||||||||||
| 65 | 2 | has 'javascript' => <<'EOF' | |||||||||||||||||||||||||||
| 66 | <script type="text/javascript"> | ||||||||||||||||||||||||||||
| 67 | jQuery(document).ready(function($) { | ||||||||||||||||||||||||||||
| 68 | $('#debugbar [data-toggle="tab"]').on('click', function(e) { | ||||||||||||||||||||||||||||
| 69 | $('#debugbar-push').addClass('open'); | ||||||||||||||||||||||||||||
| 70 | $('#debugbar').addClass('open'); | ||||||||||||||||||||||||||||
| 71 | }); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | $('.debugbar-actions .minimize-debugbar').on('click', function(e) { | ||||||||||||||||||||||||||||
| 74 | e.preventDefault(); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | $('#debugbar-push').removeClass('open'); | ||||||||||||||||||||||||||||
| 77 | $('#debugbar').removeClass('open'); | ||||||||||||||||||||||||||||
| 78 | $('#debugbar').find('.nav-tabs .active').removeClass('active'); | ||||||||||||||||||||||||||||
| 79 | $('#debugbar').find('.tab-content .active').removeClass('active'); | ||||||||||||||||||||||||||||
| 80 | }); | ||||||||||||||||||||||||||||
| 81 | }); | ||||||||||||||||||||||||||||
| 82 | </script> | ||||||||||||||||||||||||||||
| 83 | EOF | ||||||||||||||||||||||||||||
| 84 | ; | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | has 'registered' => sub { [] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 86 | 2 | has 'hide_empty' => 0; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | has 'started_at' => sub { time() }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | has 'ended_at' => sub { time() }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 duration | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Ended at - started at | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub duration { | ||||||||||||||||||||||||||
|
Subroutine
duration: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | return sprintf("%.4f", $self->ended_at - $self->started_at); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 inject | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Inject as javascript | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub inject { | ||||||||||||||||||||||||||
|
Subroutine
inject: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $content = ''; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | foreach my $monitor (@{ $self->registered }) { | |||||||||||||||||||||||||||
| 114 | 0 | $content .= $monitor->inject; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return sprintf('<script type="text/javascript">%s</script>', $content); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 render | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Loops through each monitor and renders the html | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | my $tabs = ''; | |||||||||||||||||||||||||||
| 130 | 0 | my $content = ''; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | foreach my $monitor (@{ $self->registered }) { | |||||||||||||||||||||||||||
| 133 | 0 | my $count = $monitor->count; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | next if ($self->hide_empty && !$count); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->hide_empty and not $count
MC/DC0%0/2
$self->hide_empty and not $count
$self->hide_empty
not $count
Truth table0%0/3
A and not(B)
A= $self->hide_emptyB= not $count
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | my $id = md5_sum(ref($monitor)); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $tabs .= sprintf('<li class="nav-item">' . | |||||||||||||||||||||||||||
| 140 | '<a href="#" class="nav-link" data-toggle="tab" data-target="#t-%s">%s %s (%s)</a>' . | ||||||||||||||||||||||||||||
| 141 | '</li>', $id, $monitor->icon, $monitor->name, $count); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | $content .= sprintf('<div class="tab-pane" id="t-%s">%s</div>', $id, $monitor->render); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | return sprintf( | |||||||||||||||||||||||||||
| 147 | '%s | ||||||||||||||||||||||||||||
| 148 | <div id="debugbar-push"></div> | ||||||||||||||||||||||||||||
| 149 | <div id="debugbar"> | ||||||||||||||||||||||||||||
| 150 | <div class="debugbar-header"> | ||||||||||||||||||||||||||||
| 151 | <div class="debugbar-brand"> | ||||||||||||||||||||||||||||
| 152 | <i class="icon-cubes"></i> | ||||||||||||||||||||||||||||
| 153 | </div> | ||||||||||||||||||||||||||||
| 154 | <ul class="nav nav-tabs">%s</ul> | ||||||||||||||||||||||||||||
| 155 | <div class="debugbar-actions"> | ||||||||||||||||||||||||||||
| 156 | <!--<span><i class=" icon-clock"></i>%ss</span> | --> | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | <a href="#" class="minimize-debugbar" title="Minimize debugbar"><i class="icon-down-open"></i></a> | ||||||||||||||||||||||||||||
| 159 | </div> | ||||||||||||||||||||||||||||
| 160 | </div> | ||||||||||||||||||||||||||||
| 161 | <div class="debugbar-content"> | ||||||||||||||||||||||||||||
| 162 | <div class="tab-content">%s</div> | ||||||||||||||||||||||||||||
| 163 | </div> | ||||||||||||||||||||||||||||
| 164 | </div> | ||||||||||||||||||||||||||||
| 165 | %s', | ||||||||||||||||||||||||||||
| 166 | $self->css, $tabs, $self->duration, $content, $self->javascript | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head2 stop | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Loops through each monitor and calls stop then stops the timer | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub stop { | ||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | $_->stop for @{ $self->registered }; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | $self->ended_at(time()); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 start | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Starts the timer and loops through each monitor and calls start | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | $self->started_at(time()); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | $_->start for @{ $self->registered }; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 2 | 1; | |||||||||||||||||||||||||||