Debugbar/Monitor/ValidationTiny.pm

filter: Statementstmt 25.0% 6 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 20.0% 1 / 5 Podpod 100% 3 / 3 totaltotal 31.2% 10 / 32 CC 3 SCAR 14.2
CC
3
Cov
25%
rows
6.0
__ANON__
6.0
render
2.0
CRAP 4.1
« Debugbar/Monitor/Template.pm ↑ Summary Debugbar/Monitor/Git.pm »
1 package Mojo::Debugbar::Monitor::ValidationTiny;
2 1 ▶use Mojo::Base "Mojo::Debugbar::Monitor";
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 has 'icon' => '<i class="icon-flag"></i>';
5 1 has 'name' => 'Validation';
6  
7 =head2 render
8  
9 Returns the html
10  
11 =cut
12  
13 0 ▶sub render {
Subroutine render: not called CC=1 SCAR=6.9
Pod documented
14 0 my $self = shift;
15  
16 0 return sprintf(
17 '<table class="debugbar-templates table" data-debugbar-ref="%s">
18 <thead>
19 <tr>
20 <th width="30%%">Field</th>
21 <th>Error</th>
22 </tr>
23 </thead>
24 <tbody>
25 %s
26 </tbody>
27 </table>',
28 ref($self), $self->rows
29 );
30 }
31  
32 =head2 rows
33  
34 Build the rows
35  
36 =cut
37  
38 0 ▶sub rows {
Subroutine rows: not called CC=2 SCAR=17.9
Pod documented
39 0 my $self = shift;
40  
41 0 my $time = time;
42 0 my ($sec, $min, $hour) = localtime($time);
43  
44 0 my $rows = sprintf('<tr><td colspan="2">Validation at %s:%s:%s (%s)</td></tr>', $hour, $min, $sec, scalar @{ $self->items });
45  
46 0 foreach my $item (@{ $self->items }) {
47 $rows .= sprintf(
48 '<tr>
49 <td><a href="javascript:jQuery(\'[name=%s]\').css({ background: \'red\'}).focus();">%s</a></td>
50 <td>%s</td>
51 </tr>',
52 $item->{ field }, $item->{ field }, $item->{ message }
53 0 );
54 }
55  
56 0 return $rows;
57 }
58  
59 =head2 start
60  
61 Listen for "after_dispatch" event and if there's anything in stash for validate_tiny.errors key,
62 store the field name and the error
63  
64 =cut
65  
66 0 ▶sub start {
Subroutine start: not called CC=1 SCAR=6.9
Pod documented
67 0 my $self = shift;
68  
69 0 ▶ $self->app->hook(after_dispatch => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
70 0 my $c = shift;
71  
72 0 my $errors = $c->stash('validate_tiny.errors');
73  
74 0 my @items;
75
76 0 push(@items, { field => $_, message => $errors->{ $_ } }) for keys(%$errors);
77  
78 0 $self->items(\@items);
79 0 });
80 }
81  
82 1 1;
« Debugbar/Monitor/Template.pm ↑ Summary Debugbar/Monitor/Git.pm »