File Coverage

lib/Egg/Plugin/Debug/Bar.pm
Criterion Covered Total %
statement 6 37 16.2
branch 0 10 0.0
condition 0 15 0.0
subroutine 2 9 22.2
pod n/a
total 8 71 11.2


line stmt bran cond sub pod time code
1             package Egg::Plugin::Debug::Bar;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Bar.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   492 use strict;
  1         4  
  1         42  
8 1     1   6 use warnings;
  1         2  
  1         830  
9              
10             our $VERSION= '3.00';
11              
12             my $debug_bar;
13             sub _setup {
14 0     0     my($e)= @_;
15 0 0         unless ($e->debug) {
16 0     0     $debug_bar= sub {};
  0            
17 0           return $e->next::method;
18             }
19 0           my $name_uc= $e->uc_namespace;
20 0   0       my $c= $e->config->{plugin_debug_bar} ||= {};
21 0           my $reboot_button;
22 0 0 0       if ( my $n= $ENV{"${name_uc}_FCGI_REBOOT"}
23             || $ENV{"${name_uc}_PPCGI_REBOOT"} ) {
24 0 0         my $name= $n ne 1 ? $n: 'reboot';
25             $reboot_button= sub {
26 0     0     <<END_BUTTON;
27             <input onclick="location.href='$_[0]?${name}=1'" type="button" value="Reboot" class="debug_button" />
28             END_BUTTON
29 0           };
30             }
31 0   0 0     $reboot_button ||= sub {};
  0            
32             $debug_bar= sub {
33 0     0     my($egg)= @_;
34 0           my $ctype;
35 0 0 0       return 0 if ($ctype= $e->response->content_type and $ctype!~m{^text/html});
36 0   0       my $body= $egg->response->body || return 0;
37 0 0         $$body=~m{<html.*?>.+</html.*?>}is || return 0;
38 0           my $c= $egg->config->{plugin_debug_bar};
39 0           my $path= $egg->req->path;
40 0           my $bar= <<END_BAR;
41             <style type="text/css">
42 0   0       @{[ $c->{style} || $egg->_debugbar_style ]}
  0            
43             </style>
44             <div id="debug_bar">
45             <div style="float:right">
46             <input onclick="history.back()" type="button" value="Previous Page" class="debug_button" />
47             <input onclick="location.reload()" type="button" value="Reload" class="debug_button" />
48             <input onclick="location.href='${path}'" type="button" value="Rerequest" class="debug_button" />
49             @{[ $reboot_button->($path) ]}
50             </div>
51             Egg::Plugin::Debug::Bar $VERSION
52             </div>
53             END_BAR
54 0           $$body=~s{^(.*?<body.*?>)} [$1$bar]is;
55 0           };
56 0           $e->next::method;
57             }
58             sub _output {
59 0     0     my($e)= @_;
60 0           $debug_bar->($e);
61 0           $e->next::method;
62             }
63             sub _debugbar_style {
64 0     0     <<END_STYLE;
65             #debug_bar {
66             height:18px;
67             background:#CCC;
68             border-bottom:#555 solid 1px;
69             margin:0px 0px 10px 0px;
70             font:bold 12px Times,sans-serif;
71             text-align:left;
72             padding:2px 2px 2px 10px;
73             }
74             #debug_bar .debug_button {
75             width:100px;
76             height:18px;
77             background:#AAA;
78             border:#777 solid 1px;
79             cursor:pointer;
80             }
81             END_STYLE
82             }
83              
84             1;
85              
86             __END__
87              
88             =head1 NAME
89              
90             Egg::Plugin::Debug::Bar - Plugin to bury bar for debugging under contents for Egg.
91              
92             =head1 SYNOPSIS
93              
94             use Egg qw/ Debug::Bar /;
95              
96             # dispatch.fcgi
97            
98             #!/usr/local/bin/perl
99             BEGIN {
100             $ENV{EXAMPLE_REQUEST_CLASS} ||= 'Egg::Request::FastCGI';
101             # $ENV{EGGRELEASE_FCGI_LIFE_COUNT} = 0;
102             # $ENV{EGGRELEASE_FCGI_LIFE_TIME} = 0;
103             $ENV{EGGRELEASE_FCGI_RELOAD} = 1;
104             };
105             use lib "/path/to/MyApp/lib";
106             use MyApp;
107             MyApp->handler;
108              
109             =head1 DESCRIPTION
110              
111             This plugin buries the bar for debugging under the upper part of contents at debug
112             mode.
113              
114             When it is operated by FastCGI, this is convenient. The useful function that can
115             be used in other platforms is not provided.
116              
117             $ENV{EGGRELEASE_FCGI_RELOAD} of the trigger script for FastCGI is set and used.
118             Then, the button named Reboot appears in the bar.
119             When the FastCGI process falls and it will be requested that this button be
120             pushed when the application is developed next time, come do the reload of the
121             project.
122              
123             It comes do not to have to reactivate the WEB server when developing by this.
124              
125             Especially, it is L<Module::Refresh> in FastCGI. However, I think it is convenient
126             when this plugin is used by Ki or do not exist.
127              
128             Besides, it might be good to set $ENV{EGGRELEASE_FCGI_LIFE_COUNT} and
129             $ENV{EGGRELEASE_FCGI_LIFE_TIME}, etc.
130             Please see at the document of L<Egg::Request::FastCGI> in detail.
131              
132             =head1 SEE ALSO
133              
134             L<Egg::Release>,
135             L<Egg::Request::FastCGI>,
136              
137             =head1 AUTHOR
138              
139             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
140              
141             =head1 COPYRIGHT AND LICENSE
142              
143             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
144              
145             This library is free software; you can redistribute it and/or modify
146             it under the same terms as Perl itself, either Perl version 5.8.6 or,
147             at your option, any later version of Perl 5 you may have available.
148              
149             =cut
150