view release on metacpan or search on metacpan
0.95 2005-12-07 Rhesa Rozendaal <rhesa@cpan.org>
- added "severity" attribute to reports.
- cosmetic changes in css and html
- added log report (from Log::Dispatch or STDERR)
0.94 2005-11-23 Rhesa Rozendaal <rhesa@cpan.org>
- scrollbars didn't show up after all (reported by Robert Lawson)
0.93 2005-10-05 Rhesa Rozendaal <rhesa@cpan.org>
- Made popup resizable and scrollable in IE.
0.92 2005-10-05 Rhesa Rozendaal <rhesa@cpan.org>
- Moved HTTP Headers to its own module
0.91 2005-10-04 Rhesa Rozendaal <rhesa@cpan.org>
- Added HTTP Headers report
- Updated docs to reflect availability of CAP::HtmlTidy
0.02 2005-09-22 Rhesa Rozendaal <rhesa@cpan.org>
- Added master switch in the form of $ENV{CAP_DEVPOPUP_EXEC}
(thanks to markstos and hide on #cgiapp)
- Added a hook to ::Timing at devpopup_addtiming for your own timing needs
- Added name of template in load_tmpl timing point
(thanks to Michael Graham on the mailing list)
- Cosmetic changes in html
0.01 2005-09-21 Rhesa Rozendaal <rhesa@cpan.org>
- Initial revision, basic html and a simple Timing plugin.
---
abstract: 'Runtime cgiapp info in a popup window'
author:
- 'Rhesa Rozendaal <rhesa@cpan.org>'
build_requires: {}
configure_requires:
ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.300016, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: CGI-Application-Plugin-DevPopup
requires:
CGI::Application: 4.01
HTML::Template: 0
IO::Scalar: 0
Test::More: 0
Time::HiRes: 0
resources:
repository: http://github.com/rhesa/cgi-application-plugin-devpopup
version: 1.08
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
"ABSTRACT" => "Runtime cgiapp info in a popup window",
"AUTHOR" => "Rhesa Rozendaal <rhesa\@cpan.org>",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
"DISTNAME" => "CGI-Application-Plugin-DevPopup",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "CGI::Application::Plugin::DevPopup",
"PREREQ_PM" => {
This archive contains the distribution CGI-Application-Plugin-DevPopup,
version 1.08:
Runtime cgiapp info in a popup window
This software is copyright (c) 2013 by Rhesa Rozendaal.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
name = CGI-Application-Plugin-DevPopup
version = 1.08
abstract = Runtime cgiapp info in a popup window
author = Rhesa Rozendaal <rhesa@cpan.org>
license = Perl_5
copyright_holder = Rhesa Rozendaal
[@Classic]
[Prereqs]
Test::More = 0
CGI::Application = 4.01
Time::HiRes = 0
HTML::Template = 0
IO::Scalar = 0
[MetaResources]
repository = http://github.com/rhesa/cgi-application-plugin-devpopup
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
$CGI::Application::Plugin::DevPopup::VERSION = '1.08';
}
use warnings;
use strict;
use base 'Exporter';
use HTML::Template;
use CGI::Application 4.01;
our @EXPORT = qw/ devpopup /;
my ( $head, $script, $template ); # html stuff for our screen
sub import
{
my $caller = scalar(caller);
$caller->add_callback( 'postrun', \&_devpopup_output ) if $ENV{'CAP_DEVPOPUP_EXEC'};
$caller->new_hook('devpopup_report');
goto &Exporter::import;
}
sub devpopup
{
my $app = shift; # a cgiapp object
my $dp = $app->param('__CAP_DEVPOPUP');
unless ($dp)
{
$dp = bless [], __PACKAGE__;
$app->param( '__CAP_DEVPOPUP' => $dp );
}
return $dp;
}
sub add_report
{
my $self = shift; # a devpopup object
my %params = @_;
$params{severity} ||= 'info';
push @$self, \%params;
}
sub _devpopup_output
{
my ( $self, $outputref ) = @_;
return unless $self->header_type eq 'header'; # don't operate on redirects or 'none'
my %props = $self->header_props;
my ($type) = grep /type/i, keys %props;
return if defined $type and # no type defaults to html, so we have work to do.
$props{$type} !~ /html/i; # else skip any other types.
my $devpopup = $self->devpopup;
$self->call_hook( 'devpopup_report', $outputref ); # process our callback hook
my $tmpl = HTML::Template->new(
scalarref => \$template,
die_on_bad_params => 0,
loop_context_vars => 1,
);
$tmpl->param(
reports => $devpopup,
app_class => ref($self),
runmode => $self->get_current_runmode,
);
my $o = _escape_js($tmpl->output);
my $h = _escape_js($head);
my $j = _escape_js($script . join($/, map { $_->{script} } grep exists $_->{script}, @$devpopup) );
my $js = qq{
<script language="javascript">
var devpopup_window = window.open("", "devpopup_window", "height=400,width=600,scrollbars,resizable");
devpopup_window.document.write("$h");
devpopup_window.document.write("\t<s");
devpopup_window.document.write("cript type=\\"text/javascript\\">\\n");
devpopup_window.document.write("//"+"<"+"![CDATA[\\n");
devpopup_window.document.write("$j");
devpopup_window.document.write("//]"+"]>\\n");
devpopup_window.document.write("\t<");
devpopup_window.document.write("/script>");
devpopup_window.document.write("$o");
devpopup_window.document.close();
devpopup_window.focus();
</script>
};
# insert the js code before the body close,
# if one exists
if ( $$outputref =~ m!</body>!i )
{
$$outputref =~ s!</body>!$js\n</body>!i;
}
else
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
$j;
}
$head = <<HEAD;
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Devpopup results</title>
<style type="text/css">
div.report { border: dotted 1px black; margin: 1em;}
div.report h2 { color: #000; background-color: #ddd; padding:.2em; margin-top:0;}
div.report_full, div.report_summary { padding: 0em 1em; }
a:hover, div.report h2:hover, a.print_button:hover { cursor: pointer; background-color: #eee; }
a { text-decoration: underline }
a.print_button { text-align: right; float: right; clear: right; padding: .2em; margin-right: 1em; color: #000; background-color:#ddd; border:solid 1px #444; }
// severity colors
.sev_debug { background-color: #ccffcc; color: #000; }
.sev_info { } // default
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
var d2 = document.getElementById(id2);
var s = d1.style.display;
d1.style.display = d2.style.display;
d2.style.display = s;
}
JS
$template = <<TMPL;
</head>
<body>
<h1>Devpopup report for <tmpl_var app_class> -> <tmpl_var runmode></h1>
<a href="javascript:window.print()" class="print_button">Print</a>
<div id="titles">
<ul>
<tmpl_loop reports>
<li class="sev_<tmpl_var severity>">
<a onclick="swap('#DPS<tmpl_var __counter__>','#DPR<tmpl_var __counter__>')"><tmpl_var title></a> - <tmpl_var summary>
</li>
</tmpl_loop>
</ul>
</div>
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
</body>
</html>
TMPL
1; # End of CGI::Application::Plugin::DevPopup
__END__
=head1 NAME
CGI::Application::Plugin::DevPopup - Runtime cgiapp info in a popup window
=head1 VERSION
version 1.08
=head1 SYNOPSIS
=head2 End user information
This module provides a plugin framework for displaying runtime information
about your CGI::Application app in a popup window. A sample Timing plugin is
provided to show how it works:
BEGIN { $ENV{'CAP_DEVPOPUP_EXEC'} = 1; } # turn it on for real
use CGI::Application::Plugin::DevPopup;
use CGI::Application::Plugin::DevPopup::Timing;
The rest of your application follows
...
Now whenever you access a runmode, a window pops up over your content, showing
information about how long the various stages have taken. Adding other
CAP::DevPopup plugins will get you more information. A HTML::Tidy plugin
showing you how your document conforms to W3C standards is available: see
L<CGI::Application::Plugin::HtmlTidy>.
The output consists of a Table of Contents, and a bunch of reports. A rough
translation into plain text could look like this:
Devpopup report for My::App -> add_timing
* Timings - Total runtime: 3.1178 sec.
+-----------------------------------------------------------------------+
| Timings |
+-----------------------------------------------------------------------+
| Application started at: Thu Sep 22 02:55:35 2005 |
| From To Time taken |
|-----------------------------------------------------------------------|
| init prerun 0.107513 sec. |
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
| after expensive operation load_tmpl(dp.html) 0.000379 sec. |
| load_tmpl(dp.html) postrun 0.002849 sec. |
+-----------------------------------------------------------------------+
The reports expand and collapse by clicking on the ToC entry or the report
header.
=head2 Developer information
Creating a new plugin for DevPopup is fairly simple. CAP::DevPopup registers a
new callback point (named C<devpopup_report>), which it uses to collect output
from your plugin. You can add a callback to that point, and return your
formatted output from there. The callback has this signature:
sub callback($cgiapp_class, $outputref)
You pass your output to the devpopup object by calling
$cgiapp_class->devpopup->add_report(
title => $title,
summary => $summary,
report => $body,
);
You are receiving $outputref, because DevPopup wants to be the last one to be
called in the postrun callback. If you had wanted to act at postrun time, then
please do so with this variable, and not through a callback at postrun.
=head2 The C<on> switch
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
=item o L<CGI::Application::Plugin::HtmlTidy> integrates with this module.
=item o L<CGI::Application::Plugin::TT> integrates with this module.
=back
=head1 EXPORTS
=over 4
=item * devpopup
This method is the only one exported into your module, and can be used to
access the underlying DevPopup object. See below for the methods that this
object exposes.
=back
=head1 METHODS
=over 4
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
=item * severity
An optional value specifying the importance of your report. Accepted values
are qw/debug info warning error fatal/. This value is used to color-code the
report headers.
=item * script
If you have custom javascript, then please pass it in through this field.
Otherwise if it's embedded in your report, it will break the popup window. I
will take care of the surrounding C<<script>> tags, so just the code body is
needed.
=back
=back
=head1 INSTALLATION
INSTALLATION
lib/CGI/Application/Plugin/DevPopup.pm view on Meta::CPAN
L<CGI::Application>. L<CGI::Application::Plugin::DevPopup::Timing>
=head1 AUTHOR
Rhesa Rozendaal, L<rhesa@cpan.org>
=head1 BUGS
Please report any bugs or feature requests to
L<bug-cgi-application-plugin-devpopup@rt.cpan.org>, or through the web
interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-DevPopup>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 ACKNOWLEDGEMENTS
=over
=item Mark Stosberg for the initial idea, and for pushing me to write it.
lib/CGI/Application/Plugin/DevPopup/HTTPHeaders.pm view on Meta::CPAN
}
use strict;
use warnings;
no warnings 'uninitialized'; # don't care about empty strings
use base qw/Exporter/;
sub import
{
my $c = scalar caller;
$c->add_callback( 'devpopup_report', \&_header_report );
goto &Exporter::import;
}
sub _header_report
{
my $self = shift;
my $env = _env_report($self);
my $cgi = _cgi_report($self);
my $out = $self->query->header($self->header_props);
$out =~ s/\r//g;
$self->devpopup->add_report(
title => 'HTTP Headers',
summary => 'Incoming and outgoing HTTP headers',
report => qq(
<style type="text/css">
tr.even{background-color:#eee}
</style>
<table><thead><th colspan="2">Incoming HTTP Headers</th></thead><tbody> $cgi </tbody></table>
<table><thead><th colspan="2">Outgoing HTTP Headers</th></thead><tbody><tr><td style="white-space:pre">$out</td></tr></tbody></table>
<table><thead><th colspan="2">Environment Dump</th></thead><tbody><tr><td> $env </td></tr></tbody></table>
)
lib/CGI/Application/Plugin/DevPopup/HTTPHeaders.pm view on Meta::CPAN
L<CGI::Application::Plugin::DevPopup>, L<CGI::Application>
=head1 AUTHOR
Rhesa Rozendaal, L<rhesa@cpan.org>
=head1 BUGS
Please report any bugs or feature requests to
L<bug-cgi-application-plugin-devpopup@rt.cpan.org>, or through the web
interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-DevPopup>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 COPYRIGHT & LICENSE
Copyright 2005 Rhesa Rozendaal, all rights reserved.
This program is free software; you can redistribute it and/or modify it
lib/CGI/Application/Plugin/DevPopup/Log.pm view on Meta::CPAN
package CGI::Application::Plugin::DevPopup::Log;
{
$CGI::Application::Plugin::DevPopup::Log::VERSION = '1.08';
}
use strict;
use IO::Scalar;
use base qw/Exporter/;
use vars qw($VERSION @EXPORT);
@EXPORT = qw(devpopup_log_handle);
sub import
{
my $c = scalar caller;
$c->add_callback( 'devpopup_report', \&_header_report );
goto &Exporter::import;
}
sub _header_report
{
my $self = shift;
my $log = _log_report($self);
$self->devpopup->add_report(
title => 'Logs',
summary => '',
report => qq(
<style type="text/css">
tr.even{background-color:#eee}
</style>
<table><thead><th colspan="1">Logs</th></thead><tbody> $log </tbody></table>
)
);
}
lib/CGI/Application/Plugin/DevPopup/Log.pm view on Meta::CPAN
my $r=0;
my $report = join $/, map {
$r=1-$r;
qq{<tr class="@{[$r?'odd':'even']}"><td style="white-space: pre;"> $_ </td></tr>}
}
split /\n/, $$data;
return $report;
}
sub devpopup_log_handle
{
my $this = shift;
unless (ref $this->{__DEVPOPUP_LOGFH})
{
my $data = '';
$this->{__DEVPOPUP_LOGDATA} = \$data;
my $fh = new IO::Scalar \$data;
$this->{__DEVPOPUP_LOGFH} = $fh;
}
lib/CGI/Application/Plugin/DevPopup/Log.pm view on Meta::CPAN
version 1.08
=head1 SYNOPSIS
use CGI::Application::Plugin::DevPopup;
use CGI::Application::Plugin::DevPopup::Log;
sub cgiapp_init {
# example using LogDispatch
my $log_fh = $this->devpopup_log_handle;
$this->log_config(
APPEND_NEWLINE => 1,
LOG_DISPATCH_MODULES => [
{ module => 'Log::Dispatch::Handle',
name => 'popup',
min_level => $ENV{CAP_DEVPOPUP_LOGDISPATCH_LEVEL} || 'debug',
handle => $log_fh,
},
]
);
$this->log->debug("log something");
}
The rest of your application follows
...
=head1 DESCRIPTION
CGI::Application::Plugin::DevPopup::Log will create a "Log" section in the DevPopup output. All data written to the filehandle returned by C<$this-E<gt>devpopup_log_handle> will be output.
L<CGI::Application::Plugin::LogDispatch> is very handy for this, but you can write to that filehandle anyway you'd like.
=head1 METHODS
=over
=item devpopup_log_handle
Generates a (fake) filehandle you can pass on to a logging plugin. See the Synopsis for usage.
=back
=head1 SEE ALSO
L<CGI::Application::Plugin::DevPopup>
L<CGI::Application>
L<CGI::Application::Plugin::LogDispatch>
=head1 AUTHOR
Joshua I Miller, L<unrtst@cpan.org>
=head1 BUGS
Please report any bugs or feature requests to
L<bug-cgi-application-plugin-devpopup@rt.cpan.org>, or through the web
interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-DevPopup>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 COPYRIGHT & LICENSE
Copyright 2007 Joshua Miller, all rights reserved.
This program is free software; you can redistribute it and/or modify it
lib/CGI/Application/Plugin/DevPopup/Timing.pm view on Meta::CPAN
}
use strict;
use base qw/Exporter/;
use Time::HiRes qw/gettimeofday tv_interval/;
my $start = [gettimeofday];
sub import
{
my $c = scalar caller;
$c->add_callback( 'devpopup_report', \&_timer_report );
$c->new_hook('devpopup_addtiming');
$c->add_callback( 'devpopup_addtiming', \&_add_time );
foreach my $stage (qw/ init prerun load_tmpl /)
{
$c->add_callback( $stage, sub { _add_time( shift(), $stage, @_ ) } );
}
goto &Exporter::import;
}
sub _timer_report
{
my $app = shift;
my $self = _new_or_self($app);
unshift @$self, { dec => 'start', tod => $start };
_add_time( $app, 'postrun' );
$app->devpopup->add_report(
title => 'Timings',
summary => 'Total runtime: ' . tv_interval( $self->[1]{tod}, $self->[-1]{tod} ) . ' sec.',
report => '<style>
th { text-align:left; border-bottom:solid 1px black; }
</style>' .
'Application started at: ' . scalar( gmtime( $start->[0] ) ) . ' GMT<br/>' .
'<table width="100%"><tr><th>From</th><th>To</th><th>Time taken</th></tr>' .
join(
$/,
map {
lib/CGI/Application/Plugin/DevPopup/Timing.pm view on Meta::CPAN
From To Time taken
-------------------------------------------------------------------------
init prerun 0.107513 sec.
prerun before expensive operation 0.000371 sec.
before expensive operation after expensive operation 3.006688 sec.
after expensive operation load_tmpl(dp.html) 0.000379 sec.
load_tmpl(dp.html) postrun 0.002849 sec.
=head1 ADD_TIMING
You can add your own timing points within your application by calling the hook at C<devpopup_addtiming> with a short label. The table above was created with the following code:
$self->call_hook('devpopup_addtiming', 'before expensive operation');
sleep 3;
$self->call_hook('devpopup_addtiming', 'after expensive operation');
=head1 SEE ALSO
L<CGI::Application::Plugin::DevPopup>, L<CGI::Application>
=head1 AUTHOR
Rhesa Rozendaal, L<rhesa@cpan.org>
=head1 BUGS
Please report any bugs or feature requests to
L<bug-cgi-application-plugin-devpopup@rt.cpan.org>, or through the web
interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-DevPopup>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 COPYRIGHT & LICENSE
Copyright 2005 Rhesa Rozendaal, all rights reserved.
This program is free software; you can redistribute it and/or modify it
t/01-basics.t view on Meta::CPAN
BEGIN { $ENV{CAP_DEVPOPUP_EXEC} = 1; }
{
package My::App;
use base qw/CGI::Application/;
use CGI::Application::Plugin::DevPopup;
sub setup
{
my $self = shift;
$self->add_callback('devpopup_report', 'my_report');
$self->start_mode('runmode');
$self->run_modes([ qw/runmode/ ]);
}
sub runmode
{
my $self = shift;
return '<html><body>Hi there!</body></html>';
}
sub my_report
{
my $self = shift;
my $outputref = shift;
$self->devpopup->add_report(
title => 'Test 1',
report => 'Test 1 report body',
);
}
}
$ENV{CGI_APP_RETURN_ONLY} = 1;
my $app = My::App->new;
my $output = $app->run;
t/02-production.t view on Meta::CPAN
delete $ENV{'CAP_DEVPOPUP_EXEC'};
{
package My::App;
use base qw/CGI::Application/;
use CGI::Application::Plugin::DevPopup;
sub setup
{
my $self = shift;
$self->add_callback('devpopup_report', 'my_report');
$self->start_mode('runmode');
$self->run_modes([ qw/runmode/ ]);
}
sub runmode
{
my $self = shift;
return '<html><body>Hi there!</body></html>';
}
sub my_report
{
my $self = shift;
my $outputref = shift;
$self->devpopup->add_report(
title => 'Test 1',
report => 'Test 1 report body',
);
}
}
$ENV{CGI_APP_RETURN_ONLY} = 1;
my $app = My::App->new;
my $output = $app->run;
t/03-httpheaders.t view on Meta::CPAN
{
package My::App;
use base qw/CGI::Application/;
use CGI::Application::Plugin::DevPopup;
use CGI::Application::Plugin::DevPopup::HTTPHeaders;
sub setup
{
my $self = shift;
$self->add_callback('devpopup_report', 'my_report');
$self->start_mode('runmode');
$self->run_modes([ qw/runmode/ ]);
}
sub runmode
{
my $self = shift;
return '<html><body>Hi there!</body></html>';
}
sub my_report
{
my $self = shift;
my $outputref = shift;
$self->devpopup->add_report(
title => 'Test 1',
report => 'Test 1 report body',
);
}
}
$ENV{CGI_APP_RETURN_ONLY} = 1;
$ENV{HTTP_HOST} = undef; # RT #42315
my $app = My::App->new;
t/RT53100.t view on Meta::CPAN
eval "use Log::Dispatch::Handle";
plan skip_all => "Log::Dispatch::Handle required for this test" if $@;
eval "use Test::NoWarnings";
plan skip_all => "Test::NoWarnings required for this test" if $@;
plan tests => 2;
my $log = bless {}, 'CGI::Application::Plugin::DevPopup::Log';
like eval
{
my $fh = $log->devpopup_log_handle;
my $handle = Log::Dispatch::Handle->new(
name => 'test RT53100',
min_level => 'debug',
handle => $fh,
);
$handle->log(level => "debug", message => "we live!");
my $report = $log->_log_report;
}, qr/we live!/, "no fatal warnings";