HTTP::Engine::FirePHP - Log to FirePHP from within HTTP::Engine
use HTTP::Engine::Response; use HTTP::Engine::FirePHP; sub request_handler { my $req = shift; my $res = HTTP::Engine::Response->new; # ... $res->fire_php->log('foo'); # ... $res; }
If you are developing a web application and don't want to or can't check the error log, the traditional way is to include debug messages in the HTML page. However, this messes up the layout and mixes content with logging; the two really need to be separate.
FirePHP is a Firebug plugin which enables you to log to your Firebug Console by sending certain HTTP headers in the HTTP response. FirePHP is not just useful for PHP, though; any server-side application that can manipulate HTTP headers can log to Firebug.
The FirePHP response headers use the Wildfire protocol. The CPAN module FirePHP::Dispatcher can generate these headers.
This module then integrates FirePHP::Dispatcher with HTTP::Engine. By simply using this module, HTTP::Engine::Response gets a fire_php() accessor through which you can log to FirePHP.
fire_php()
my $res = HTTP::Engine::Response->new; $res->fire_php->log('foo');
This method is placed into the HTTP::Engine::Response class. The first time you access it, a new HTTP::Engine::FirePHP::Dispatcher object is created. You can use all logging methods of FirePHP::Dispatcher; please refer to that module's manpage.
Note that - despite what it says in FirePHP::Dispatcher - you don't have to call finalize(); this is done automatically each time something is logged.
finalize()
When you load the response into Firefox, open the Firebug Console and you will find the logged messages there.
When you restart the HTTP::Engine-based server, be sure to do a shift-reload of the relevant page in Firefox; this ensures that headers aren't cached. If you don't do this, you might see remnant headers from previous responses.
my $dbh = DBI->connect(...); my $res = HTTP::Engine::Response->new; $dbh->trace(2, $res->get_fire_php_fh); # Now the trace of all calls to $dbh will be sent to FirePHP
This method is placed into the HTTP::Engine::Response class. It returns a filehandle that sends every output to FirePHP - see PerlIO::via::ToFirePHP for details. A typical use is to pass this filehandle to DBI's trace() method and have all trace output sent to FirePHP.
trace()
This method requires PerlIO::via::ToFirePHP to be installed.
This module monkeypatches HTTP::Engine::Response, so it's not ideal encapsulation. Also, FirePHP::Dispatcher expects to work with a HTTP::Headers object, but HTTP::Engine::Response uses HTTP::Headers::Fast, so this module also munges the latter module's inheritance to make it look like the right class.
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
See perlmodinstall for information and options on installing Perl modules.
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you. Or see http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/.
The development version lives at http://github.com/hanekomu/http-engine-firephp/. Instead of sending patches, please fork this project using the standard git and github infrastructure.
Marcel Grünauer, <marcel@cpan.org>
<marcel@cpan.org>
Copyright 2009 by Marcel Grünauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTTP::Engine::FirePHP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Engine::FirePHP
CPAN shell
perl -MCPAN -e shell install HTTP::Engine::FirePHP
For more information on module installation, please visit the detailed CPAN module installation guide.