Debugbar/Monitor/Git.pm

filter: Statementstmt 13.9% 6 / 43 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.6% 1 / 6 Podpod 100% 4 / 4 totaltotal 20.7% 11 / 53 CC 3 SCAR 13.5
CC
3
Cov
14%
rows
6.0
__ANON__
6.0
render
2.0
CRAP 3.9
« Debugbar/Monitor/ValidationTiny.pm ↑ Summary Debugbar/Monitor.pm »
1 package Mojo::Debugbar::Monitor::Git;
2 1 ▶use Mojo::Base "Mojo::Debugbar::Monitor";
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 has 'icon' => '<i class="icon-tree-conifer"></i>';
5 1 has 'name' => 'Git';
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>Value</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">Git 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 $home = $self->app->home;
73 0 my $gitinfo = $self->git_info($home);
74 0 my @items;
75  
76 0 push(@items, { field => $_, message => $gitinfo->{ $_ } }) for keys(%$gitinfo);
77  
78 0 $self->items(\@items);
79 0 });
80 }
81  
82 =head2 git_info
83  
84 Get the git info
85  
86 =cut
87  
88 0 ▶sub git_info {
Subroutine git_info: not called CC=1 SCAR=6.9
Pod documented
89 0 my $self = shift;
90 0 my $home = shift;
91  
92 0 my $command = "git -P --work-tree=$home log -n1 --no-color --decorate";
93 0 my $old_path = $ENV{'PATH'};
94 0 $old_path =~ /(.+)/;
95 0 $old_path = $1;
96 0 $ENV{'PATH'} = $old_path;
97  
98 0 my $git_output = `$command`;
99  
100 0 $git_output =~ //;
101 0 my @lines = split /[\r\n]+/, $git_output;
102  
103 0 my $line = shift @lines;
104 0 my ($commit, $branch) = $line =~ /commit (\w+) .+ -> ([^,]+),.+/g;
105  
106 0 $line = shift @lines;
107 0 my ($author) = $line =~ /Author: (.+) <(.+)/;
108  
109 0 $line = shift @lines;
110 0 my ($date) = $line =~ /Date: (.+)/;
111  
112 0 my $comment = join ', ', @lines;
113  
114 return {
115 0 branch => $branch,
116 commit => $commit,
117 author => $author,
118 date => $date,
119 comment => $comment
120 };
121 }
122  
123 1 1;
« Debugbar/Monitor/ValidationTiny.pm ↑ Summary Debugbar/Monitor.pm »