Hi! Please consider following me on twitter: @hanekomu.

Log to FirePHP via an PerlIO layer

I have released PerlIO::via::ToFirePHP. This PerlIO layer sends everything it receives to FirePHP. When constructing a filehandle using this layer using open(), you need to pass an object of type FirePHP::Dispatcher that has been initialized with a HTTP::Headers object.

use PerlIO::via::ToFirePHP;
my $fire_php = FirePHP::Dispatcher->new(HTTP::Headers->new);
open my $fh, '>:via(ToFirePHP)', $fire_php;

Everything you print on the filehandle will be sent to FirePHP.

A typical use of this PerlIO layer is to send DBI trace output to FirePHP:

use PerlIO::via::ToFirePHP;

my $dbh = DBI->connect(...);

open my $fh, '>:via(ToFirePHP)',
    FirePHP::Dispatcher->new($http_headers_object);
$dbh->trace(2, $fh);

Now the trace output of all calls to that database handle will be sent to FirePHP.

The PerlIO layer is implemented in PerlIO::via::ToFirePHP instead of just PerlIO::via::FirePHP because of a bug in PerlIO::via in perl 5.10.0 and earlier versions. If we used just PerlIO::via::FirePHP, we would not be able to use the shorthand layer notation of open my $fh, ':>via(FirePHP), $fire_php. PerlIO::via would look for a PUSHED method in package FirePHP. There is no such method, but because FirePHP::Dispatcher has been loaded, the namespace FirePHP has been autovivified. So PerlIO::via would stop looking. This bug seems to be fixed in perl 5.10.1.

In the next article I will show a complete example of how to send DBI trace output to FirePHP in an HTTP::Engine demo web application.

Tags: , .

Write a comment | Bookmark and Share

posted at: 12:05 | path: /dev | permalink | 1 comment | 0 trackbacks

Sebastian Willert wrote at 2009-06-12 14:12:

Ok, got the message, I'll release a non-dev version in the next few days ;)

Thanks for your interest in FirePHP::Dispatcher

Comments are closed for this story.

Trackbacks are closed for this story.