Catalyst::Plugin::Firebug - Catalyst plugin for Firebug Lite


Catalyst-Action-Firebug documentation Contained in the Catalyst-Action-Firebug distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::Firebug - Catalyst plugin for Firebug Lite

SYNOPSIS

Top

    use Catalyst qw/Firebug/;

DESCRIPTION

Top

Catalyst plugin for Firebug Lite.

If you load this plugin, and your app running on debug mode or $ENV{FIREBUG_DEBUG} is set, this plugin insert firebug lite tags to its output automaticaly.

CONFIGURATION

Top

You can specify firebug.js path by following config:

    $c->config->{firebug}{path} = '/path/to/firebug.js';

Default path is '/js/firebug/firebug.js'.

SEE ALSO

Top

Firebug, http://getfirebug.com/

Firebug Lite, http://getfirebug.com/lite.html

EXTENDED METHODS

Top

finalize

AUTHOR

Top

Daisuke Murase <typester@cpan.org>

COPYRIGHT

Top


Catalyst-Action-Firebug documentation Contained in the Catalyst-Action-Firebug distribution.
package Catalyst::Plugin::Firebug;
use strict;
use warnings;

use NEXT;

our $VERSION = '0.02';

sub finalize {
    my $c = shift;
    return $c->NEXT::finalize unless $c->debug || $ENV{FIREBUG_DEBUG};

    if ($c->res->content_type =~ /html/) {
        $c->log->debug('enable firebug lite');

        my $firebug = $c->uri_for( $c->config->{firebug}{path} || '/js/firebug/firebug.js' );

        my $body = $c->res->body;

        if ($body =~ m!<head.*?>.*?</head>!is) {
            $body =~ s!(<head.*?>(?:.*?))(</head>)!$1<script type="text/javascript" src="$firebug"></script>$2!is;
        }
        else {
            $body .= qq{<script type="text/javascript" src="$firebug"></script>};
        }

        if ($body =~ m!<html.*?>.*?</html>!is) {
            $body =~ s!(<html.*?)>!$1 debug="true">!is;
        }
        else {
            $body = qq{<html debug="true">$body</html>};
        }

        $c->res->body( $body );
    }

    $c->NEXT::finalize;
}

1;