Plugin/Firebug.pm

filter: Statementstmt 92.0% 23 / 25 Branchbran 50.0% 4 / 8 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 73.9% 34 / 46 CC 7 SCAR 18.7
CC
7
Cov
76%
finalize
8.8
BEGIN
1.0
BEGIN
1.0
CRAP 6.5
« Action/Firebug.pm ↑ Summary
1 package Catalyst::Plugin::Firebug;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use NEXT;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.02';
8  
9 =head1 NAME
10  
11 Catalyst::Plugin::Firebug - Catalyst plugin for Firebug Lite
12  
13 =head1 SYNOPSIS
14  
15 use Catalyst qw/Firebug/;
16  
17 =head1 DESCRIPTION
18  
19 Catalyst plugin for Firebug Lite.
20  
21 If you load this plugin, and your app running on debug mode or $ENV{FIREBUG_DEBUG} is set,
22 this plugin insert firebug lite tags to its output automaticaly.
23  
24 =head1 CONFIGURATION
25  
26 You can specify firebug.js path by following config:
27  
28 $c->config->{firebug}{path} = '/path/to/firebug.js';
29  
30 Default path is '/js/firebug/firebug.js'.
31  
32 =head1 SEE ALSO
33  
34 Firebug, http://getfirebug.com/
35  
36 Firebug Lite, http://getfirebug.com/lite.html
37  
38 =head1 EXTENDED METHODS
39  
40 =head2 finalize
41  
42 =cut
43  
44 1 ▶sub finalize {
Subroutine finalize: called CC=7 SCAR=21.8
Pod documented
45 1 my $c = shift;
46 1 ▶ return $c->NEXT::finalize unless $c->debug || $ENV{FIREBUG_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->debug or $ENV{"FIREBUG_DEBUG"} 0 1 1
Condition33%1/3
$c->debug or $ENV{"FIREBUG_DEBUG"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$c->debug or $ENV{"FIREBUG_DEBUG"}
$c->debug $ENV{"FIREBUG_DEBUG"}
Truth table33%1/3
A or B
A= $c->debugB= $ENV{"FIREBUG_DEBUG"}
ABresult
1X1
011
000
47  
48 1 ▶ if ($c->res->content_type =~ /html/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->res->content_type =~ /html/) 1 0 1
49 1 $c->log->debug('enable firebug lite');
50  
51 1 ▶ my $firebug = $c->uri_for( $c->config->{firebug}{path} || '/js/firebug/firebug.js' );
Condition50%1/2
$c->config->{'firebug'}{'path'} || '/js/firebug/firebug.js'
l!l
01
MC/DC0%0/1
$c->config->{'firebug'}{'path'} || '/js/firebug/firebug.js'
$c->config->{'firebug'}{'path'}
Truth table50%1/2
A
A= $c->config->{'firebug'}{'path'}
Aresult
11
00
52  
53 1 my $body = $c->res->body;
54  
55 1 ▶ if ($body =~ m!<head.*?>.*?</head>!is) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ m[<head.*?>.*?</head>]is) { } 1 0 1
56 1 $body =~ s!(<head.*?>(?:.*?))(</head>)!$1<script type="text/javascript" src="$firebug"></script>$2!is;
57 }
58 else {
59 0 $body .= qq{<script type="text/javascript" src="$firebug"></script>};
60 }
61  
62 1 ▶ if ($body =~ m!<html.*?>.*?</html>!is) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ m[<html.*?>.*?</html>]is) { } 1 0 1
63 1 $body =~ s!(<html.*?)>!$1 debug="true">!is;
64 }
65 else {
66 0 $body = qq{<html debug="true">$body</html>};
67 }
68  
69 1 $c->res->body( $body );
70 }
71  
72 1 $c->NEXT::finalize;
73 }
74  
75 =head1 AUTHOR
76  
77 Daisuke Murase <typester@cpan.org>
78  
79 =head1 COPYRIGHT
80  
81 This program is free software; you can redistribute
82 it and/or modify it under the same terms as Perl itself.
83  
84 The full text of the license can be found in the
85 LICENSE file included with this module.
86  
87 =cut
88  
89 3 1;
« Action/Firebug.pm ↑ Summary