| 1 | package Mojo::Debugbar::Monitor::Session; | ||||||||||||
| 2 | 1 | ▶ | use Mojo::Base "Mojo::Debugbar::Monitor"; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | 1 | ▶ | use Mojo::JSON qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | has 'icon' => '<i class="icon-cloud"></i>'; | |||||||||||
| 8 | 1 | has 'name' => 'Session'; | |||||||||||
| 9 | |||||||||||||
| 10 | =head2 render | ||||||||||||
| 11 | |||||||||||||
| 12 | Returns the html | ||||||||||||
| 13 | |||||||||||||
| 14 | =cut | ||||||||||||
| 15 | |||||||||||||
| 16 | 0 | ▶ | sub render { | ||||||||||
|
Subroutine
render: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||
| 18 | |||||||||||||
| 19 | 0 | return sprintf( | |||||||||||
| 20 | '<table class="debugbar-templates table" data-debugbar-ref="%s"> | ||||||||||||
| 21 | <thead> | ||||||||||||
| 22 | <tr> | ||||||||||||
| 23 | <th width="30%%">Key</th> | ||||||||||||
| 24 | <th>Value</th> | ||||||||||||
| 25 | </tr> | ||||||||||||
| 26 | </thead> | ||||||||||||
| 27 | <tbody> | ||||||||||||
| 28 | %s | ||||||||||||
| 29 | </tbody> | ||||||||||||
| 30 | </table>', | ||||||||||||
| 31 | ref($self), $self->rows | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | =head2 rows | ||||||||||||
| 36 | |||||||||||||
| 37 | Build the rows | ||||||||||||
| 38 | |||||||||||||
| 39 | =cut | ||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | sub rows { | ||||||||||
|
Subroutine
rows: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||
| 43 | |||||||||||||
| 44 | 0 | my $time = time; | |||||||||||
| 45 | 0 | my ($sec, $min, $hour) = localtime($time); | |||||||||||
| 46 | |||||||||||||
| 47 | 0 | my $rows = sprintf('<tr><td colspan="2">Session at %s:%s:%s (%s)</td></tr>', $hour, $min, $sec, scalar @{ $self->items }); | |||||||||||
| 48 | |||||||||||||
| 49 | 0 | foreach my $item (@{ $self->items }) { | |||||||||||
| 50 | $rows .= sprintf( | ||||||||||||
| 51 | '<tr> | ||||||||||||
| 52 | <td>%s</td> | ||||||||||||
| 53 | <td>%s</td> | ||||||||||||
| 54 | </tr>', | ||||||||||||
| 55 | 0 | ▶ | $item->{ key }, $item->{ value } || '' | ||||||||||
|
Condition0%0/2
$item->{'value'} || ''
MC/DC0%0/1
$item->{'value'} || ''
$item->{'value'}
Truth table0%0/2
A
A= $item->{'value'}
| |||||||||||||
| 56 | ); | ||||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 0 | return $rows; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | =head2 start | ||||||||||||
| 63 | |||||||||||||
| 64 | Listen for "after_dispatch" event and collect session data | ||||||||||||
| 65 | |||||||||||||
| 66 | =cut | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub start { | ||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||
| 70 | |||||||||||||
| 71 | 0 | my @items; | |||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | $self->app->hook(after_dispatch => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 75 | 0 | my $c = shift; | |||||||||||
| 76 | |||||||||||||
| 77 | 0 | my $session = $c->session; | |||||||||||
| 78 | |||||||||||||
| 79 | 0 | for my $key (keys(%$session)) { | |||||||||||
| 80 | 0 | my $value = $session->{ $key }; | |||||||||||
| 81 | 0 | ▶ | $value = encode_json($value) if ref($value); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | |||||||||||||
| 83 | 0 | push(@items, { key => $key, value => $value }); | |||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | }); | |||||||||||
| 86 | |||||||||||||
| 87 | 0 | $self->items(\@items); | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 1 | 1; | |||||||||||