blib/lib/Plack/Middleware/GitRevisionInfo.pm

filter: Statementstmt 32.5% 13 / 40 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 33.3% 3 / 9 Podpod 100% 1 / 1 totaltotal 26.9% 17 / 63 CC 5 SCAR 20.7
CC
5
Cov
26%
_handle_response
20.0
_get_revision_info
6.0
__ANON__
2.0
CRAP 7.9
↑ Summary
1 package Plack::Middleware::GitRevisionInfo;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 extends 'Plack::Middleware';
7  
8 1 our $VERSION = '0.002';
9  
10 1 has 'path' => (
11 is => 'ro',
12 );
13  
14 has 'git_command' => (
15 is => 'ro',
16 0 ▶ default => sub { 'LC_ALL=C git log -1 --pretty=medium' }
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 1 );
18  
19 0 ▶sub call {
Subroutine call: not called CC=1 SCAR=6.9
Pod documented
20 0 my ($self, $env) = @_;
21  
22 0 my $response = $self->app->($env);
23 0 ▶ $self->response_cb($response, sub { $self->_handle_response(shift) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 }
25  
26 0 ▶sub _handle_response {
Subroutine _handle_response: not called CC=4 SCAR=30.0
27 0 my ($self, $response) = @_;
28 0 my $header = Plack::Util::headers($response->[1]);
29 0 my $content_type = $header->get('Content-Type');
30 0 my $path = $self->path;
31
32 0 ▶ return unless defined $content_type && $content_type =~ qr[text/html] && $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content_type and $content_type =~ qr"text/html" and $path 0 0 0
Condition0%0/6
defined $content_type and $content_type =~ qr"text/html" and $path
!ll&&!rl&&r
000
defined $content_type and $content_type =~ qr"text/html"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $content_type and $content_type =~ qr"text/html" and $path
defined $content_type $content_type =~ qr"text/html" $path
Truth table0%0/4
A and B and C
A= defined $content_typeB= $content_type =~ qr"text/html"C= $path
ABCresult
0XX0
10X0
1100
1111
33
34 0 my $body = [];
35 0 ▶ Plack::Util::foreach( $response->[2], sub { push @$body, $_[0] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 $body = join '', @$body;
37  
38 0 $body .= $self->_get_revision_info;
39
40 0 $response->[2] = [$body];
41 0 $header->set('Content-Length', length $body);
42  
43 0 return;
44 }
45  
46 0 ▶sub _get_revision_info {
Subroutine _get_revision_info: not called CC=2 SCAR=17.9
47 0 my $self = shift;
48 0 ▶ if ( -d $self->path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $self->path) 0 0 0
49 0 my $path = $self->path;
50 0 my $command = $self->git_command;
51 0 my $output = `cd $path;$command`;
52  
53 0 my ($sha) = $output =~ m/commit\s([^\n]*)\n/s;
54 0 my ($date) = $output =~ m/Date:\s+([^\n]*)\n/s;
55  
56 0 return qq[<!-- Revision: $sha Date: $date -->];
57 }
58 0 return;
59 }
60  
61 1 1;
62 =head1 NAME
63  
64 Plack::Middleware::GitRevisionInfo - Middleware that appends git revision information to html
65  
66 =head1 SYNOPSIS
67  
68 use Plack::Builder;
69  
70 builder {
71 enable "Plack::Middleware::GitReivisionInfo", path => '../repo';
72 $app;
73 };
74  
75 =head1 DESCRIPTION
76  
77 L<Plack::Middleware::GitRevisionInfo> will display the git revision
78 information in the source of an html document in the following format:
79  
80 <!-- REVISION #:... DATE:MM/DD/YYYY -->
81  
82 =head1 ARGUMENTS
83  
84 This middleware accepts the following arguments.
85  
86 =head2 path
87  
88 This is the path to the git repository. This is a required argument.
89  
90 =head1 SEE ALSO
91  
92 L<Plack>, L<Plack::Middleware>, L<Moo>
93  
94 =head1 AUTHOR
95  
96 Logan Bell, C<< <logie@cpan.org> >>
97  
98 =head1 COPYRIGHT & LICENSE
99  
100 Copyright 2012, Logan Bell
101  
102 This program is free software; you can redistribute it and/or modify
103 it under the same terms as Perl itself.
104  
105 =cut
106  
↑ Summary