blib/lib/Plack/Middleware/Firebug/Lite.pm

filter: Statementstmt 47.2% 17 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 6 / 10 Podpod 100% 2 / 2 totaltotal 42.3% 25 / 59 CC 5 SCAR 19.9
CC
5
Cov
38%
__ANON__
20.0
prepare_app
6.0
call
2.0
CRAP 7.3
↑ Summary
1 # ABSTRACT: Plack middleware to insert Firebug Lite code into HTML.
2 package Plack::Middleware::Firebug::Lite;
3 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $Plack::Middleware::Firebug::Lite::VERSION = '0.2.3';
5 }
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Plack::Middleware::Firebug::Lite - Plack middleware to insert Firebug Lite code into HTML.
12  
13 =head1 VERSION
14  
15 version 0.2.3
16  
17 =head1 DESCRIPTION
18  
19 This module will insert Firebug Lite code into HTML.
20 Currently it will check if Content-Type is C<text/html>.
21  
22 =head1 SYNOPSIS
23  
24 use Plack::Builder;
25 builder {
26 # Use stable channel from official site.
27 enable 'Firebug::Lite';
28  
29 # or, use local copy
30 enable 'Firebug::Lite', url => '/local/path/to/firebug-lite.js';
31  
32 $app;
33 }
34  
35 =cut
36  
37 1 ▶use parent 'Plack::Middleware';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Plack::Util::Accessor qw/url/;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 0 ▶sub call {
Subroutine call: not called CC=1 SCAR=6.9
Pod documented
43 0 my ($self, $env) = @_;
44  
45 0 my $res = $self->app->($env);
46 0 ▶ Plack::Util::response_cb($res, sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
47 0 my $res = shift;
48  
49 0 my $h = Plack::Util::headers($res->[1]);
50  
51 # Only process text/html.
52 0 my $ct = $h->get('Content-Type');
53 0 ▶ return unless defined $ct and $ct =~ qr{text/html};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ct and $ct =~ qr"text/html" 0 0 0
Condition0%0/3
defined $ct and $ct =~ qr"text/html"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ct and $ct =~ qr"text/html"
defined $ct $ct =~ qr"text/html"
Truth table0%0/3
A and B
A= defined $ctB= $ct =~ qr"text/html"
ABresult
0X0
100
111
54  
55 # Don't touch compressed content.
56 0 ▶ return if defined $h->get('Content-Encoding');
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->get("Content-Encoding") 0 0 0
57  
58 # Concat all content, and if response body is undefined then ignore it.
59 0 my $body = [];
60 0 ▶ Plack::Util::foreach($res->[2], sub { push @$body, $_[0]; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 0 $body = join '', @$body;
62  
63 0 my $url = encode_entities($self->url, '<>&"');
64  
65 # Insert Firebug Lite code and replace it.
66 0 $body =~ s{^(.*)\</body\s*\>}{$1<script src="$url" type="text/javascript"></script></body>}is;
67 0 $res->[2] = [$body];
68 0 $h->set('Content-Length', length $body);
69  
70 0 return;
71 0 });
72 }
73  
74 0 ▶sub prepare_app {
Subroutine prepare_app: not called CC=2 SCAR=17.9
Pod documented
75 0 my $self = shift;
76 0 ▶ $self->url('//getfirebug.com/firebug-lite.js') unless defined $self->url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->url 0 0 0
77 }
78  
79 =head1 AUTHOR
80  
81 Gea-Suan Lin, C<< <gslin at gslin.org> >>
82  
83 =head1 LICENSE AND COPYRIGHT
84  
85 Copyright 2011 Gea-Suan Lin.
86  
87 This software is released under 3-clause BSD license. See
88 L<http://www.opensource.org/licenses/bsd-license.php> for more
89 information.
90  
91 =cut
92  
93 1 1;
↑ Summary