| 1 | package Catalyst::Action::Firebug; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use base qw/Catalyst::Action/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use NEXT; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Catalyst::Action::Firebug - Catalyst action for embedding Firebug Lite tag | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub end : ActionClass('Firebug') { | ||||||||||||||||||||||||||||
| 17 | my ($self, $c) = @_; | ||||||||||||||||||||||||||||
| 18 | $c->forward( $c->view('TT') ); | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # or combination with Action::RenderView | ||||||||||||||||||||||||||||
| 22 | sub render : ActionClass('RenderView') {} | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub end : ActionClass('Firebug') { | ||||||||||||||||||||||||||||
| 25 | my ($self, $c) = @_; | ||||||||||||||||||||||||||||
| 26 | $c->forward('render'); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Catalyst action for Firebug Lite. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | If your app running on debug mode or $ENV{FIREBUG_DEBUG} is set, | ||||||||||||||||||||||||||||
| 34 | this action insert firebug lite tags to its output automaticaly. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | $c->config->{firebug}{path} = '/path/to/firebug.js'; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 KEYS | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =over 4 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item path | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | URL path of firebug.js. The default value is '/js/firebug/firebug.js'. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item expand_panel | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | If it's true value, firebug panel is opened when page loading. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | And you can use FIREBUG_EXPAND env instead of this key. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Firebug, http://getfirebug.com/ | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Firebug Lite, http://getfirebug.com/lite.html | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 EXTENDED METHODS | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 execute | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=9 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 1 | my ($controller, $c) = @_; | |||||||||||||||||||||||||||
| 71 | 1 | my $res = $self->NEXT::execute(@_); | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | return $res unless $c->debug || $ENV{FIREBUG_DEBUG}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->debug or $ENV{"FIREBUG_DEBUG"}
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"}
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | if ($c->res->content_type =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 1 | $c->log->debug('enable firebug lite'); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 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'
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'}
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | my $body = $c->res->body; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | if ($body =~ m!<head.*?>.*?</head>!is) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | $body =~ s!(<head.*?>(?:.*?))(</head>)!$1<script type="text/javascript" src="$firebug"></script>$2!is; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||
| 85 | 0 | $body .= qq{<script type="text/javascript" src="$firebug"></script>}; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | if ($c->config->{firebug}{expand_panel} || $ENV{FIREBUG_EXPAND}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->config->{"firebug"}{"expand_panel"} or $ENV{"FIREBUG_EXPAND"}
MC/DC0%0/2
$c->config->{"firebug"}{"expand_panel"} or $ENV{"FIREBUG_EXPAND"}
$c->config->{"firebug"}{"expand_panel"}
$ENV{"FIREBUG_EXPAND"}
Truth table33%1/3
A or B
A= $c->config->{"firebug"}{"expand_panel"}B= $ENV{"FIREBUG_EXPAND"}
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | if ($body =~ m!<html.*?>.*?</html>!is) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | $body =~ s!(<html.*?)>!$1 debug="true">!is; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||
| 93 | 0 | $body = qq{<html debug="true">$body</html>}; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | $c->res->body( $body ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | $res; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Daisuke Murase <typester@cpan.org> | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 110 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 113 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | 1; | |||||||||||||||||||||||||||