Catalyst::Plugin::Acme::LOLCAT - IM IN UR CATALYST APLACASHUN REWRITIN YUR OUTPUTS.


Catalyst-Plugin-Acme-LOLCAT documentation Contained in the Catalyst-Plugin-Acme-LOLCAT distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::Acme::LOLCAT - IM IN UR CATALYST APLACASHUN REWRITIN YUR OUTPUTS.

VERSION

Top

Version 0.03

SYNOPSIS

Top

See Acme::LOLCAT if you don't already know what this will do to your Catalyst plain text and HTML output.

 use Catalyst qw/
                 Your::Regular::Plugins
                 Acme::LOLCAT
                /;

 # And observe the corrected output of your application

AUTHOR

Top

Ashley Pond V, ashley at cpan.org.

BUGS

Top

I love bugs! Hymenoptera, dictyoptera, coleoptera, all of them.

Expects valid nesting. May sometimes interfere with tags that should be literal, like <script> and <style>, when it's not present.

TODO

Top

Targeted tags in config file?

SUPPORT

Top

You can find documentation for this module with the perldoc command.

   perldoc Catalyst::Plugin::Acme::LOLCAT

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Catalyst-Plugin-Acme-LOLCAT

* CPAN Ratings

http://cpanratings.perl.org/d/Catalyst-Plugin-Acme-LOLCAT

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Acme-LOLCAT

* Search CPAN

http://search.cpan.org/dist/Catalyst-Plugin-Acme-LOLCAT

SEE ALSO

Top

Acme::LOLCAT, Catalyst::Plugin::Acme::Scramble, Catalyst, Catalyst::Runtime.

COPYRIGHT & LICENSE

Top


Catalyst-Plugin-Acme-LOLCAT documentation Contained in the Catalyst-Plugin-Acme-LOLCAT distribution.
package Catalyst::Plugin::Acme::LOLCAT;

use strict;
use Acme::LOLCAT ();

our $VERSION = "0.03";

my $skip = qr/\Ascript|style\z/;

sub finalize {
    my $c = shift;

    return $c->NEXT::finalize unless $c->response->body
        and
        $c->response->content_type =~ m,^text/(plain|html),;

    if ( $1 eq 'plain' )
    {
        $c->response->{body} = Acme::LOLCAT::translate($c->response->{body});
    }
    else
    {
        require HTML::TokeParser;
        my $p = HTML::TokeParser->new( \$c->response->{body} );
        my $repaired = '';
        my @queue;

        while ( my $t = $p->get_token() )
        {
            push @queue, $t->[1] if $t->[0] eq 'S'; # assumes well-formed
            pop @queue if $t->[0] eq 'E'
                or 
                ( $t->[0] eq 'S' and $t->[-1] =~ m,/>\z, ); # self-closer

            if ( 
                 $t->[0] eq 'T'
                 and
                 not $t->[2]
                 and
                 not grep /$skip/, @queue )
            {
                my $txt = $t->[1] =~ /\w/ ? Acme::LOLCAT::translate($t->[1]) : $t->[1];
                $repaired .= $txt;
            }
            else
            {
                $repaired .= ( $t->[0] eq 'T' ) ? $t->[1] : $t->[-1];
            }
        }
        $c->response->{body} = $repaired;
    }

    $c->NEXT::finalize;
}

1; # End of Catalyst::Plugin::Acme::LOLCAT