App::Mobirc::Plugin::HTMLFilter::CompressHTML - compress the html filter


mobirc documentation Contained in the mobirc distribution.

Index


Code Index:

NAME

Top

App::Mobirc::Plugin::HTMLFilter::CompressHTML - compress the html filter

DESCRIPTION

Top

compress the html filter for mobirc

AUTHOR

Top

cho45

SEE ALSO

Top

App::Mobirc


mobirc documentation Contained in the mobirc distribution.

package App::Mobirc::Plugin::HTMLFilter::CompressHTML;
# vim:expandtab:
use strict;
use MooseX::Plaggerize::Plugin;
use App::Mobirc::Util;
use App::Mobirc::Validator;

hook html_filter => sub {
    my ($self, $global_context, $req, $content) = validate_hook('html_filter', @_);

    my $bsize = length $content;

    $content =~ s{<!--.+?-->}{}gs;
    $content =~ s{[ \t\f]+}{ }g;
    # 可読性保持のため若干めんどいことをやっている
    $content =~ s{([ \t\f]*[\r\n]+[ \t\f]*)+}{\n}g;
    $content =~ s{> ([^<])}{>$1}g;

    my $asize   = length $content;
    my $rate    = sprintf("%03.1f", 100 - ($asize / $bsize * 100));
    my $packets = sprintf("%0.1f D.%.1f", $asize / 128, ($bsize - $asize) / 128);

    DEBUG "Compress before->$bsize after->$asize $rate% packets->$packets";

    return ( $req, $content);
};

1;
__END__