diff -Nru libhtml-packer-perl-1.000/Changes libhtml-packer-perl-1.002/Changes
--- libhtml-packer-perl-1.000/Changes 2011-01-17 06:44:08.000000000 +0000
+++ libhtml-packer-perl-1.002/Changes 2011-06-07 05:42:21.000000000 +0000
@@ -1,12 +1,31 @@
Revision history for HTML-Packer
+1.002 2011-06-07
+ - Raised version number.
+
+1.001_002 2011-05-20
+ - Fixed tests. Thanks to Kent Fredric.
+ - Changed possible values for do_javascript options.
+
+1.001_001 2011-04-12
+ - Added html5 option.
+ - Removed no_cdata option.
+ - Added tests.
+ - Minor bugfixes.
+ - Cleanup.
+
+1.001001 2011-03-07
+ - Changed requirements to Regexp::RegGrp 1.000001 due to "undefined submatches bug" in Regexp::RegGrp.
+ - Added accessors.
+ - Added tests.
+
1.000 2011-01-17
- Changed versioning.
- Raised major version due to changes in versioning.
- Changed requirements to Regexp::RegGrp 1.000 due to changes in versioning.
0.05_06 2011-01-05
- - Changed requirements to Regexp::RegGrp 0.04
+ - Changed requirements to Regexp::RegGrp 0.04.
0.05_05 2010-12-03
- Added no_cdata option.
diff -Nru libhtml-packer-perl-1.000/debian/changelog libhtml-packer-perl-1.002/debian/changelog
--- libhtml-packer-perl-1.000/debian/changelog 2011-03-12 17:04:32.000000000 +0000
+++ libhtml-packer-perl-1.002/debian/changelog 2011-06-10 10:59:39.000000000 +0000
@@ -1,3 +1,14 @@
+libhtml-packer-perl (1.002-1) unstable; urgency=low
+
+ * New upstream release
+ * Bump Standards Version to 3.9.2 (no changes)
+ * debian/control: update version dependency for libregexp-reggrp-perl
+ * Add myself to Uploaders and Copyright
+ * debian/copyright: update copyright statement years for files under
+ inc/Module/*
+
+ -- Jotam Jr. Trejo Fri, 10 Jun 2011 00:00:55 -0600
+
libhtml-packer-perl (1.000-1) unstable; urgency=low
[ gregor herrmann ]
diff -Nru libhtml-packer-perl-1.000/debian/control libhtml-packer-perl-1.002/debian/control
--- libhtml-packer-perl-1.000/debian/control 2011-03-12 17:03:38.000000000 +0000
+++ libhtml-packer-perl-1.002/debian/control 2011-06-10 12:07:37.000000000 +0000
@@ -3,11 +3,12 @@
Priority: optional
Build-Depends: debhelper (>= 8)
Build-Depends-Indep: perl, libtest-pod-perl,
- libregexp-reggrp-perl (>= 1.000001)
+ libregexp-reggrp-perl (>= 1.002)
Maintainer: Debian Perl Group
Uploaders: Ernesto Hernández-Novich (USB) ,
- gregor herrmann
-Standards-Version: 3.9.1
+ gregor herrmann ,
+ Jotam Jr. Trejo
+Standards-Version: 3.9.2
Homepage: http://search.cpan.org/dist/HTML-Packer/
Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libhtml-packer-perl/
Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libhtml-packer-perl/
@@ -15,7 +16,7 @@
Package: libhtml-packer-perl
Architecture: all
Depends: ${perl:Depends}, ${misc:Depends},
- libregexp-reggrp-perl (>= 1.000001)
+ libregexp-reggrp-perl (>= 1.002)
Recommends: libcss-packer-perl, libjavascript-packer-perl
Description: HTML code cleaner
HTML::Packer is a Perl library for HTML cleanup that does comment and
diff -Nru libhtml-packer-perl-1.000/debian/copyright libhtml-packer-perl-1.002/debian/copyright
--- libhtml-packer-perl-1.000/debian/copyright 2011-03-12 17:02:34.000000000 +0000
+++ libhtml-packer-perl-1.002/debian/copyright 2011-06-10 10:59:39.000000000 +0000
@@ -8,14 +8,15 @@
License: Artistic or GPL-1+
Files: inc/Module/*
-Copyright: 2002-2010, Adam Kennedy
- 2002-2010, Audrey Tang
- 2002-2010, Brian Ingerson
+Copyright: 2002-2011, Adam Kennedy
+ 2002-2011, Audrey Tang
+ 2002-2011, Brian Ingerson
License: Artistic or GPL-1+
Files: debian/*
Copyright: 2009-2011, Ernesto Hernández-Novich (USB)
2011, gregor herrmann
+ 2011, Jotam Jr. Trejo
License: Artistic or GPL-1+
License: Artistic
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/AutoInstall.pm libhtml-packer-perl-1.002/inc/Module/Install/AutoInstall.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/AutoInstall.pm 2011-01-17 16:45:30.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/AutoInstall.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Base.pm libhtml-packer-perl-1.002/inc/Module/Install/Base.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Base.pm 2011-01-17 16:45:29.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Base.pm 2011-06-07 05:44:37.000000000 +0000
@@ -4,7 +4,7 @@
use strict 'vars';
use vars qw{$VERSION};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
}
# Suspend handler for "redefined" warnings
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Can.pm libhtml-packer-perl-1.002/inc/Module/Install/Can.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Can.pm 2011-01-17 16:45:31.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Can.pm 2011-06-07 05:44:37.000000000 +0000
@@ -9,7 +9,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Fetch.pm libhtml-packer-perl-1.002/inc/Module/Install/Fetch.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Fetch.pm 2011-01-17 16:45:31.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Fetch.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Include.pm libhtml-packer-perl-1.002/inc/Module/Install/Include.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Include.pm 2011-01-17 16:45:30.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Include.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Makefile.pm libhtml-packer-perl-1.002/inc/Module/Install/Makefile.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Makefile.pm 2011-01-17 16:45:29.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Makefile.pm 2011-06-07 05:44:37.000000000 +0000
@@ -8,7 +8,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Metadata.pm libhtml-packer-perl-1.002/inc/Module/Install/Metadata.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Metadata.pm 2011-01-17 16:45:29.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Metadata.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
@@ -515,6 +515,7 @@
'GNU Free Documentation license' => 'unrestricted', 1,
'GNU Affero General Public License' => 'open_source', 1,
'(?:Free)?BSD license' => 'bsd', 1,
+ 'Artistic license 2\.0' => 'artistic_2', 1,
'Artistic license' => 'artistic', 1,
'Apache (?:Software )?license' => 'apache', 1,
'GPL' => 'gpl', 1,
@@ -550,9 +551,9 @@
sub _extract_bugtracker {
my @links = $_[0] =~ m#L<(
- \Qhttp://rt.cpan.org/\E[^>]+|
- \Qhttp://github.com/\E[\w_]+/[\w_]+/issues|
- \Qhttp://code.google.com/p/\E[\w_\-]+/issues/list
+ https?\Q://rt.cpan.org/\E[^>]+|
+ https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
+ https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
)>#gx;
my %links;
@links{@links}=();
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/Win32.pm libhtml-packer-perl-1.002/inc/Module/Install/Win32.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/Win32.pm 2011-01-17 16:45:31.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/Win32.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install/WriteAll.pm libhtml-packer-perl-1.002/inc/Module/Install/WriteAll.pm
--- libhtml-packer-perl-1.000/inc/Module/Install/WriteAll.pm 2011-01-17 16:45:30.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install/WriteAll.pm 2011-06-07 05:44:37.000000000 +0000
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '1.00';
+ $VERSION = '1.01';
@ISA = qw{Module::Install::Base};
$ISCORE = 1;
}
diff -Nru libhtml-packer-perl-1.000/inc/Module/Install.pm libhtml-packer-perl-1.002/inc/Module/Install.pm
--- libhtml-packer-perl-1.000/inc/Module/Install.pm 2011-01-17 16:45:29.000000000 +0000
+++ libhtml-packer-perl-1.002/inc/Module/Install.pm 2011-06-07 05:44:36.000000000 +0000
@@ -31,7 +31,7 @@
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
- $VERSION = '1.00';
+ $VERSION = '1.01';
# Storage for the pseudo-singleton
$MAIN = undef;
@@ -467,4 +467,4 @@
1;
-# Copyright 2008 - 2010 Adam Kennedy.
+# Copyright 2008 - 2011 Adam Kennedy.
diff -Nru libhtml-packer-perl-1.000/lib/HTML/Packer.pm libhtml-packer-perl-1.002/lib/HTML/Packer.pm
--- libhtml-packer-perl-1.000/lib/HTML/Packer.pm 2011-01-17 06:44:26.000000000 +0000
+++ libhtml-packer-perl-1.002/lib/HTML/Packer.pm 2011-06-07 05:42:40.000000000 +0000
@@ -8,14 +8,32 @@
# -----------------------------------------------------------------------------
-our $VERSION = '1.000';
+our $VERSION = '1.002';
-our @TAGS = (
+our @BOOLEAN_ACCESSORS = (
+ 'remove_comments',
+ 'remove_newlines',
+ 'no_compress_comment',
+ 'html5',
+);
+
+our @JAVASCRIPT_OPTS = ( 'clean', 'obfuscate', 'shrink', 'best' );
+our @CSS_OPTS = ( 'minify', 'pretty' );
+
+our $REQUIRED_JAVASCRIPT_PACKER = '1.002001';
+our $REQUIRED_CSS_PACKER = '1.000001';
+
+our @SAVE_SPACE_ELEMENTS = (
'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'button', 'cite',
'del', 'dfn', 'em', 'font', 'i', 'input', 'ins', 'kbd', 'label', 'q',
's', 'samp', 'select', 'small', 'strike', 'strong', 'sub', 'sup', 'u', 'var'
);
+our @VOID_ELEMENTS = (
+ 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input',
+ 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
+);
+
# Some regular expressions are from HTML::Clean
our $COMMENT = '((?>\s*))()((?>\s*))';
@@ -74,7 +92,7 @@
our $NEWLINES_TAGS = [
{
- regexp => '(\s*)(<\s*\/?\s*(?:' . join( '|', @TAGS ) . ')[^>]*>)(\s*)',
+ regexp => '(\s*)(<\s*\/?\s*(?:' . join( '|', @SAVE_SPACE_ELEMENTS ) . ')\b[^>]*>)(\s*)',
replacement => sub {
return sprintf( '%s%s%s', $_[0]->{submatches}->[0] ? ' ' : '', $_[0]->{submatches}->[1], $_[0]->{submatches}->[2] ? ' ' : '' );
},
@@ -105,20 +123,73 @@
}
];
+our @REGGRPS = ( 'newlines', 'newlines_tags', 'whitespaces', 'void_elements' );
+
+our $GLOBAL_REGGRP = 'global';
+
+##########################################################################################
+
+{
+ no strict 'refs';
+
+ foreach my $field ( @BOOLEAN_ACCESSORS ) {
+ next if defined *{ __PACKAGE__ . '::' . $field }{CODE};
+
+ *{ __PACKAGE__ . '::' . $field} = sub {
+ my ( $self, $value ) = @_;
+
+ $self->{'_' . $field} = $value ? 1 : undef if ( defined( $value ) );
+
+ return $self->{'_' . $field};
+ };
+ }
+
+ foreach my $reggrp ( @REGGRPS, $GLOBAL_REGGRP ) {
+ next if defined *{ __PACKAGE__ . '::reggrp_' . $reggrp }{CODE};
+
+ *{ __PACKAGE__ . '::reggrp_' . $reggrp } = sub {
+ my ( $self ) = shift;
+
+ return $self->{ '_reggrp_' . $reggrp };
+ };
+ }
+}
+
+sub do_javascript {
+ my ( $self, $value ) = @_;
+
+ if ( defined( $value ) ) {
+ if ( grep( $value eq $_, @JAVASCRIPT_OPTS ) ) {
+ $self->{_do_javascript} = $value;
+ }
+ elsif ( ! $value ) {
+ $self->{_do_javascript} = undef;
+ }
+ }
+
+ return $self->{_do_javascript};
+}
+
+sub do_stylesheet {
+ my ( $self, $value ) = @_;
+
+ if ( defined( $value ) ) {
+ if ( grep( $value eq $_, @CSS_OPTS ) ) {
+ $self->{_do_stylesheet} = $value;
+ }
+ elsif ( ! $value ) {
+ $self->{_do_stylesheet} = undef;
+ }
+ }
+
+ return $self->{_do_stylesheet};
+}
+
sub init {
my $class = shift;
my $self = {};
- eval {
- require JavaScript::Packer;
- };
- $self->{can_do_javascript} = $@ ? 0 : 1;
- $self->{javascript_packer} = undef;
- eval {
- require CSS::Packer;
- };
- $self->{can_do_stylesheet} = $@ ? 0 : 1;
- $self->{css_packer} = undef;
+ bless( $self, $class );
$self->{whitespaces}->{reggrp_data} = $WHITESPACES;
$self->{newlines}->{reggrp_data} = $NEWLINES;
@@ -140,25 +211,17 @@
{
regexp => $COMMENT,
replacement => sub {
- my $opts = $_[0]->{opts} || {};
- my $remove_comments = _get_opt( $opts, 'remove_comments' );
- my $remove_newlines = _get_opt( $opts, 'remove_newlines' );
-
- return $remove_comments ? (
- $remove_newlines ? ' ' : (
+ return $self->remove_comments() ? (
+ $self->remove_newlines() ? ' ' : (
( $_[0]->{submatches}->[0] =~ /\n/s or $_[0]->{submatches}->[2] =~ /\n/s ) ? "\n" : ''
)
) : '';
},
store => sub {
- my $opts = $_[0]->{opts} || {};
- my $remove_comments = _get_opt( $opts, 'remove_comments' );
- my $remove_newlines = _get_opt( $opts, 'remove_newlines' );
-
- my $ret = $remove_comments ? '' : (
- ( ( not $remove_newlines and $_[0]->{submatches}->[0] =~ /\n/s ) ? "\n" : '' ) .
+ my $ret = $self->remove_comments() ? '' : (
+ ( ( not $self->remove_newlines() and $_[0]->{submatches}->[0] =~ /\n/s ) ? "\n" : '' ) .
$_[0]->{submatches}->[1] .
- ( ( not $remove_newlines and $_[0]->{submatches}->[2] =~ /\n/s ) ? "\n" : '' )
+ ( ( not $self->remove_newlines() and $_[0]->{submatches}->[2] =~ /\n/s ) ? "\n" : '' )
);
return $ret;
@@ -171,24 +234,25 @@
},
store => sub {
my ( $opening, undef, $content, $closing ) = @{$_[0]->{submatches}};
- my $opts = $_[0]->{opts} || {};
if ( $content ) {
- if ( $opening =~ /<\s*script[^>]*(?:java|ecma)script[^>]*>/ and $self->{javascript_packer} ) {
- my $do_javascript = _get_opt( $opts, 'do_javascript' );
- if ( $do_javascript ) {
- my $no_cdata = _get_opt( $opts, 'no_cdata' );
- $self->{javascript_packer}->minify( \$content, { compress => $do_javascript } );
- unless ( $no_cdata ) {
+ my $opening_re = '<\s*script' . ( $self->html5() ? '[^>]*>' : '[^>]*(?:java|ecma)script[^>]*>' );
+
+ if ( $opening =~ /$opening_re/i ) {
+ $opening =~ s/ type="(text\/)?(java|ecma)script"//i if ( $self->html5() );
+
+ if ( $self->javascript_packer() and $self->do_javascript() ) {
+ $self->javascript_packer()->minify( \$content, { compress => $self->do_javascript() } );
+
+ unless ( $self->html5() ) {
$content = '/**/';
}
}
}
- elsif ( $opening =~ /<\s*style[^>]*text\/css[^>]*>/ and $self->{css_packer} ) {
- my $do_stylesheet = _get_opt( $opts, 'do_stylesheet' );
- if ( $do_stylesheet ) {
- $self->{css_packer}->minify( \$content, { compress => $do_stylesheet } );
- $content = "\n" . $content if ( $do_stylesheet eq 'pretty' );
+ elsif ( $opening =~ /<\s*style[^>]*text\/css[^>]*>/ ) {
+ if ( $self->css_packer() and $self->do_stylesheet() ) {
+ $self->css_packer()->minify( \$content, { compress => $self->do_stylesheet() } );
+ $content = "\n" . $content if ( $self->do_stylesheet() eq 'pretty' );
}
}
}
@@ -196,12 +260,8 @@
$content = '';
}
- # I don't like this, but
- # $self->{whitespaces}->{reggrp}->exec( \$opening );
- # will not work. It isn't initialized jet.
- # If someone has a better idea, please let me know
- $self->_process_wrapper( 'whitespaces', \$opening );
- $self->_process_wrapper( 'whitespaces', \$closing );
+ $self->reggrp_whitespaces()->exec( \$opening );
+ $self->reggrp_whitespaces()->exec( \$closing );
return $opening . $content . $closing;
},
@@ -209,19 +269,27 @@
}
];
+ $self->{void_elements}->{reggrp_data} = [
+ {
+ regexp => '<\s*((?:' . join( '|', @VOID_ELEMENTS ) . ')\b[^>]*)\s*\/>',
+ replacement => sub {
+ return '<' . $_[0]->{submatches}->[0] . '>';
+ },
+ modifier => 'ism'
+ }
+ ];
+
map {
- $self->{$_}->{reggrp} = Regexp::RegGrp->new( { reggrp => $self->{$_}->{reggrp_data} } );
- } ( 'newlines', 'newlines_tags', 'whitespaces' );
+ $self->{ '_reggrp_' . $_ } = Regexp::RegGrp->new( { reggrp => $self->{$_}->{reggrp_data} } );
+ } @REGGRPS;
- $self->{global}->{reggrp} = Regexp::RegGrp->new(
+ $self->{ '_reggrp_' . $GLOBAL_REGGRP } = Regexp::RegGrp->new(
{
- reggrp => $self->{global}->{reggrp_data},
+ reggrp => $self->{$GLOBAL_REGGRP}->{reggrp_data},
restore_pattern => qr//
}
);
- bless( $self, $class );
-
return $self;
}
@@ -247,7 +315,7 @@
return undef;
}
- my $html = \'';
+ my $html;
my $cont = 'void';
if ( defined( wantarray ) ) {
@@ -260,84 +328,71 @@
$html = ref( $input ) ? $input : \$input;
}
- if ( $self->{can_do_javascript} and not $self->{javascript_packer_isset} ) {
- $self->{javascript_packer} = eval {
- JavaScript::Packer->init();
- };
- $self->{javascript_packer_isset} = 1;
- }
-
- if ( $self->{can_do_stylesheet} and not $self->{css_packer_isset} ) {
- $self->{css_packer} = eval {
- CSS::Packer->init();
- };
- $self->{css_packer_isset} = 1;
- }
-
- if ( ref( $opts ) ne 'HASH' ) {
- carp( 'Second argument must be a hashref of options! Using defaults!' ) if ( $opts );
- $opts = {
- remove_comments => 0,
- remove_newlines => 0,
- do_javascript => '', # minify, shrink, base62
- do_stylesheet => '', # pretty, minify
- no_compress_comment => 0,
- no_cdata => 0
- };
- }
- else {
- $opts->{remove_comments} = $opts->{remove_comments} ? 1 : 0;
- $opts->{remove_newlines} = $opts->{remove_newlines} ? 1 : 0;
- $opts->{do_javascript} = (
- grep( $opts->{do_javascript}, ( 'minify', 'shrink', 'base62' ) ) &&
- $self->{javascript_packer}
- ) ? $opts->{do_javascript} : '';
-
- $opts->{do_stylesheet} = (
- grep( $opts->{do_stylesheet}, ( 'minify', 'pretty' ) ) &&
- $self->{css_packer}
- ) ? $opts->{do_stylesheet} : '';
+ if ( ref( $opts ) eq 'HASH' ) {
+ foreach my $field ( @BOOLEAN_ACCESSORS ) {
+ $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) );
+ }
- $opts->{no_compress_comment} = $opts->{no_compress_comment} ? 1 : 0;
- $opts->{no_cdata} = $opts->{no_cdata} ? 1 : 0;
+ $self->do_javascript( $opts->{do_javascript} ) if ( defined( $opts->{do_javascript} ) );
+ $self->do_stylesheet( $opts->{do_stylesheet} ) if ( defined( $opts->{do_stylesheet} ) );
}
- if ( not $opts->{no_compress_comment} and ${$html} =~ /$PACKER_COMMENT/s ) {
+ if ( not $self->no_compress_comment() and ${$html} =~ /$PACKER_COMMENT/s ) {
my $compress = $1;
if ( $compress eq '_no_compress_' ) {
return ( $cont eq 'scalar' ) ? ${$html} : undef;
}
}
- $self->{global}->{reggrp}->exec( $html, $opts );
- $self->{whitespaces}->{reggrp}->exec( $html, $opts );
- if ( $opts->{remove_newlines} ) {
- $self->{newlines_tags}->{reggrp}->exec( $html );
- $self->{newlines}->{reggrp}->exec( $html );
+ $self->reggrp_global()->exec( $html );
+ $self->reggrp_whitespaces()->exec( $html );
+ if ( $self->remove_newlines() ) {
+ $self->reggrp_newlines_tags()->exec( $html );
+ $self->reggrp_newlines()->exec( $html );
+ }
+ if ( $self->html5() ) {
+ $self->reggrp_void_elements()->exec( $html );
}
- $self->{global}->{reggrp}->restore_stored( $html );
+ $self->reggrp_global()->restore_stored( $html );
return ${$html} if ( $cont eq 'scalar' );
}
-sub _get_opt {
- my ( $opts_hash, $opt ) = @_;
+sub javascript_packer {
+ my $self = shift;
- $opts_hash ||= {};
- $opt ||= '';
+ unless ( $self->{_checked_javascript_packer} ) {
+ eval "use JavaScript::Packer $REQUIRED_JAVASCRIPT_PACKER;";
- my $ret = '';
+ unless ( $@ ) {
+ $self->{_javascript_packer} = eval {
+ JavaScript::Packer->init();
+ };
+ }
- $ret = $opts_hash->{$opt} if ( defined( $opts_hash->{$opt} ) );
+ $self->{_checked_javascript_packer} = 1;
+ }
- return $ret;
+ return $self->{_javascript_packer};
}
-sub _process_wrapper {
- my ( $self, $reg_name, $in, $opts ) = @_;
+sub css_packer {
+ my $self = shift;
+
+ unless ( $self->{_checked_css_packer} ) {
+ eval "use CSS::Packer $REQUIRED_CSS_PACKER;";
+
+ unless ( $@ ) {
+ $self->{_css_packer} = eval {
+ CSS::Packer->init();
+ };
+ }
+
+ $self->{_checked_css_packer} = 1;
+ }
- $self->{$reg_name}->{reggrp}->exec( $in, $opts );
+ return $self->{_css_packer};
}
1;
@@ -350,7 +405,7 @@
=head1 VERSION
-Version 1.000
+Version 1.002
=head1 DESCRIPTION
@@ -387,7 +442,7 @@
=item do_javascript
-Defines compression level for javascript. Possible values are 'minify', 'shrink' and 'base62'.
+Defines compression level for javascript. Possible values are 'clean', 'obfuscate', 'shrink' and 'best'.
Default is no compression for javascript.
This option only takes effect if L is installed.
@@ -403,7 +458,11 @@
-Is set by default.
+Is not set by default.
+
+=item html5
+
+If set to a true value closing slashes will be removed from void elements.
=back
@@ -413,8 +472,8 @@
=head1 BUGS
-Please report any bugs or feature requests to C, or through
-the web interface at L. I will be notified, and then you'll
+Please report any bugs or feature requests through
+the web interface at L. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
diff -Nru libhtml-packer-perl-1.000/Makefile.PL libhtml-packer-perl-1.002/Makefile.PL
--- libhtml-packer-perl-1.000/Makefile.PL 2011-01-17 06:45:46.000000000 +0000
+++ libhtml-packer-perl-1.002/Makefile.PL 2011-05-22 10:01:40.000000000 +0000
@@ -5,9 +5,10 @@
all_from 'lib/HTML/Packer.pm';
test_requires 'Test::More' => 0;
-requires 'Regexp::RegGrp' => "1.000";
+requires 'Regexp::RegGrp' => "1.001_001";
repository 'http://github.com/nevesenin/html-packer-perl';
+bugtracker 'http://github.com/nevesenin/html-packer-perl/issues';
clean_files 't/html/s?-got.html';
diff -Nru libhtml-packer-perl-1.000/MANIFEST libhtml-packer-perl-1.002/MANIFEST
--- libhtml-packer-perl-1.000/MANIFEST 2011-01-05 06:25:42.000000000 +0000
+++ libhtml-packer-perl-1.002/MANIFEST 2011-05-22 10:01:40.000000000 +0000
@@ -15,9 +15,11 @@
lib/HTML/Packer.pm
Makefile.PL
MANIFEST
+META.yml
README
t/00-load.t
-t/01-io.t
+t/01-interface.t
+t/02-io.t
t/html/s1-expected.html
t/html/s1.html
t/html/s2-expected.html
diff -Nru libhtml-packer-perl-1.000/META.yml libhtml-packer-perl-1.002/META.yml
--- libhtml-packer-perl-1.000/META.yml 1970-01-01 00:00:00.000000000 +0000
+++ libhtml-packer-perl-1.002/META.yml 2011-06-07 05:44:38.000000000 +0000
@@ -0,0 +1,29 @@
+---
+abstract: 'Another HTML code cleaner'
+author:
+ - 'Merten Falk, C<< >>'
+build_requires:
+ ExtUtils::MakeMaker: 6.42
+ Test::More: 0
+configure_requires:
+ ExtUtils::MakeMaker: 6.42
+distribution_type: module
+generated_by: 'Module::Install version 1.01'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+module_name: HTML::Packer
+name: HTML-Packer
+no_index:
+ directory:
+ - inc
+ - t
+requires:
+ Regexp::RegGrp: 1.001_001
+ perl: 5.8.9
+resources:
+ bugtracker: http://github.com/nevesenin/html-packer-perl/issues
+ license: http://dev.perl.org/licenses/
+ repository: http://github.com/nevesenin/html-packer-perl
+version: 1.002
diff -Nru libhtml-packer-perl-1.000/README libhtml-packer-perl-1.002/README
--- libhtml-packer-perl-1.000/README 2011-01-17 06:46:07.000000000 +0000
+++ libhtml-packer-perl-1.002/README 2011-05-22 10:01:40.000000000 +0000
@@ -21,6 +21,9 @@
You can also look for information at:
+ github
+ http://github.com/nevesenin/html-packer-perl
+
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Packer
diff -Nru libhtml-packer-perl-1.000/t/01-interface.t libhtml-packer-perl-1.002/t/01-interface.t
--- libhtml-packer-perl-1.000/t/01-interface.t 1970-01-01 00:00:00.000000000 +0000
+++ libhtml-packer-perl-1.002/t/01-interface.t 2011-05-22 10:01:40.000000000 +0000
@@ -0,0 +1,113 @@
+#!perl -T
+
+use Test::More;
+
+my $not = 39;
+
+SKIP: {
+ eval { use HTML::Packer; };
+
+ skip( 'HTML::Packer not installed!', $not ) if ( $@ );
+
+ plan tests => $not;
+
+ my $packer = HTML::Packer->init();
+
+ ok( ! $packer->remove_comments(), 'Default value for remove_comments.' );
+ ok( ! $packer->remove_newlines(), 'Default value for remove_newlines.' );
+ ok( ! $packer->no_compress_comment(), 'Default value for no_compress_comment.' );
+ ok( ! $packer->html5(), 'Default value for no_cdata.' );
+ ok( ! $packer->do_javascript(), 'Default value for do_javascript.' );
+ ok( ! $packer->do_stylesheet(), 'Default value for do_stylesheet.' );
+
+ $packer->remove_comments( 1 );
+ ok( $packer->remove_comments(), 'Set remove_comments.' );
+ $packer->remove_comments( 0 );
+ ok( ! $packer->remove_comments(), 'Unset remove_comments.' );
+
+ $packer->remove_newlines( 1 );
+ ok( $packer->remove_newlines(), 'Set remove_newlines.' );
+ $packer->remove_newlines( 0 );
+ ok( ! $packer->remove_newlines(), 'Unset remove_newlines.' );
+
+ $packer->no_compress_comment( 1 );
+ ok( $packer->no_compress_comment(), 'Set no_compress_comment.' );
+ $packer->no_compress_comment( 0 );
+ ok( ! $packer->no_compress_comment(), 'Unset no_compress_comment.' );
+
+ $packer->html5( 1 );
+ ok( $packer->html5(), 'Set html5.' );
+ $packer->html5( 0 );
+ ok( ! $packer->html5(), 'Unset html5.' );
+
+ $packer->do_javascript( 'clean' );
+ is( $packer->do_javascript(), 'clean', 'Set do_javascript to "clean".' );
+ $packer->do_javascript( 'shrink' );
+ is( $packer->do_javascript(), 'shrink', 'Set do_javascript to "shrink".' );
+ $packer->do_javascript( 'obfuscate' );
+ is( $packer->do_javascript(), 'obfuscate', 'Set do_javascript to "obfuscate".' );
+ $packer->do_javascript( 'foo' );
+ is( $packer->do_javascript(), 'obfuscate', 'Setting do_javascript to "foo" failed.' );
+ $packer->do_javascript( '' );
+ ok( ! $packer->do_javascript(), 'Unset do_javascript.' );
+ $packer->do_javascript( 'bar' );
+ ok( ! $packer->do_javascript(), 'Setting do_javascript to "bar" failed.' );
+
+ $packer->do_stylesheet( 'minify' );
+ is( $packer->do_stylesheet(), 'minify', 'Set do_stylesheet to "minify".' );
+ $packer->do_stylesheet( 'pretty' );
+ is( $packer->do_stylesheet(), 'pretty', 'Set do_stylesheet to "pretty".' );
+ $packer->do_stylesheet( 'foo' );
+ is( $packer->do_stylesheet(), 'pretty', 'Setting do_stylesheet to "foo" failed.' );
+ $packer->do_stylesheet( '' );
+ ok( ! $packer->do_stylesheet(), 'Unset do_stylesheet.' );
+ $packer->do_stylesheet( 'bar' );
+ ok( ! $packer->do_stylesheet(), 'Setting do_stylesheet to "bar" failed.' );
+
+ eval "use JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER;";
+ if ( $@ ) {
+ ok( ! $packer->javascript_packer(), 'JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' );
+ }
+ else {
+ isa_ok( $packer->javascript_packer(), 'JavaScript::Packer', 'JavaScript::Packer installed.' );
+ }
+
+ eval "use CSS::Packer $HTML::Packer::REQUIRED_CSS_PACKER;";
+ if ( $@ ) {
+ ok( ! $packer->css_packer(), 'CSS::Packer >= ' . $HTML::Packer::REQUIRED_CSS_PACKER . ' not installed.' );
+ }
+ else {
+ isa_ok( $packer->css_packer(), 'CSS::Packer', 'CSS::Packer installed.' );
+ }
+
+ my $str = '';
+
+ $packer->minify( \$str, {} );
+
+ ok( ! $packer->remove_comments(), 'Default value for remove_comments is still set.' );
+ ok( ! $packer->remove_newlines(), 'Default value for remove_newlines is still set.' );
+ ok( ! $packer->no_compress_comment(), 'Default value for no_compress_comment is still set.' );
+ ok( ! $packer->html5(), 'Default value for html5 is still set.' );
+ ok( ! $packer->do_javascript(), 'Default value for do_javascript is still set.' );
+ ok( ! $packer->do_stylesheet(), 'Default value for do_stylesheet is still set.' );
+
+ $packer->minify(
+ \$str,
+ {
+ remove_comments => 1,
+ remove_newlines => 1,
+ no_compress_comment => 1,
+ html5 => 1,
+ do_javascript => 'clean',
+ do_stylesheet => 'minify'
+ }
+ );
+
+ ok( $packer->remove_comments(), 'Set remove_comments again.' );
+ ok( $packer->remove_newlines(), 'Set remove_newlines again.' );
+ ok( $packer->no_compress_comment(), 'Set no_compress_comment again.' );
+ ok( $packer->html5(), 'Set html5 again.' );
+ ok( $packer->do_javascript(), 'Set do_javascript to "clean" again.' );
+ ok( $packer->do_stylesheet(), 'Set do_stylesheet to "minify" again.' );
+
+}
\ No newline at end of file
diff -Nru libhtml-packer-perl-1.000/t/01-io.t libhtml-packer-perl-1.002/t/01-io.t
--- libhtml-packer-perl-1.000/t/01-io.t 2011-01-05 06:25:42.000000000 +0000
+++ libhtml-packer-perl-1.002/t/01-io.t 1970-01-01 00:00:00.000000000 +0000
@@ -1,149 +0,0 @@
-#!perl -T
-
-# =========================================================================== #
-
-use Test::More;
-
-my $js_input = <
-
-
-
- alert('test');
-
-link
-
-1 < /a>
-
-
-
-
- < a href="/"> link 2
- < / a >
-
-
-
-EOT
-
-my $css_input = <
-
- foo {
- asdf:asdf;
- ew:12;
- }
-
-
-link
-
-1 < /a>
-
-
-
-
- < a href="/"> link 2
- < / a >
-
-
-EOT
-
-my $js_expected_comp = 'link 1 link 2 ';
-my $js_expected_nocdata = 'link 1 link 2 ';
-my $js_expected_nocomp = 'link 1 link 2 ';
-
-my $css_expected_comp = 'link 1 link 2 ';
-my $css_expected_nocomp = 'link 1 link 2 ';
-
-my $not = 9;
-
-SKIP: {
- eval( 'use HTML::Packer;' );
-
- skip( 'HTML::Packer not installed!', $not ) if ( $@ );
-
- plan tests => $not;
-
- minTest( 's1', undef, 'Test without opts.' );
- minTest( 's2', { remove_newlines => 1 }, 'Test remove_newlines.' );
- minTest( 's3', { remove_comments => 1 }, 'Test remove_comments.' );
- minTest( 's4', { remove_comments => 1, remove_newlines => 1 }, 'Test remove_newlines and remove_comments.' );
- minTest( 's5', { remove_comments => 1, remove_newlines => 1 }, 'Test _no_compress_ comment.' );
- minTest( 's6', { remove_comments => 1, remove_newlines => 1, no_compress_comment => 1 }, 'Test _no_compress_ comment with no_compress_comment option.' );
-
- my $packer = HTML::Packer->init();
- my $js_comp_input = $js_input;
- my $js_cdata_input = $js_input;
- $packer->minify( \$js_comp_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'minify' } );
- $packer->minify( \$js_cdata_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'minify', no_cdata => 1 } );
-
- eval( 'require JavaScript::Packer' );
- if ( $@ ) {
- is( $js_comp_input, $js_expected_nocomp, 'Test do_javascript. JavaScript::Packer not installed.' );
- is( $js_cdata_input, $js_expected_nocomp, 'Test do_javascript 2. JavaScript::Packer not installed.' );
- }
- else {
- is( $js_comp_input, $js_expected_comp, 'Test do_javascript. JavaScript::Packer installed.' );
- is( $js_cdata_input, $js_expected_nocdata, 'Test do_javascript 2. JavaScript::Packer installed.' );
- }
-
- $packer->minify( \$css_input, { remove_comments => 1, remove_newlines => 1, do_stylesheet => 'pretty' } );
-
- eval( 'require CSS::Packer' );
- if ( $@ ) {
- is( $css_input, $css_expected_nocomp, 'Test do_stylesheet. CSS::Packer not installed.' );
- }
- else {
- is( $css_input, $css_expected_comp, 'Test do_stylesheet. CSS::Packer installed.' );
- }
-}
-
-sub filesMatch {
- my $file1 = shift;
- my $file2 = shift;
- my $a;
- my $b;
-
- while (1) {
- $a = getc($file1);
- $b = getc($file2);
-
- if (!defined($a) && !defined($b)) { # both files end at same place
- return 1;
- }
- elsif (
- !defined($b) || # file2 ends first
- !defined($a) || # file1 ends first
- $a ne $b
- ) { # a and b not the same
- return 0;
- }
- }
-}
-
-sub minTest {
- my $filename = shift;
- my $opts = shift || {};
- my $message = shift || '';
-
- open(INFILE, 't/html/' . $filename . '.html') or die("couldn't open file");
- open(GOTFILE, '>t/html/' . $filename . '-got.html') or die("couldn't open file");
-
- my $html = join( '', );
-
- my $packer = HTML::Packer->init();
-
- $packer->minify( \$html, $opts );
- print GOTFILE $html;
- close(INFILE);
- close(GOTFILE);
-
- open(EXPECTEDFILE, 't/html/' . $filename . '-expected.html') or die("couldn't open file");
- open(GOTFILE, 't/html/' . $filename . '-got.html') or die("couldn't open file");
- ok(filesMatch(GOTFILE, EXPECTEDFILE), $message );
- close(EXPECTEDFILE);
- close(GOTFILE);
-}
-
diff -Nru libhtml-packer-perl-1.000/t/02-io.t libhtml-packer-perl-1.002/t/02-io.t
--- libhtml-packer-perl-1.000/t/02-io.t 1970-01-01 00:00:00.000000000 +0000
+++ libhtml-packer-perl-1.002/t/02-io.t 2011-05-22 10:01:40.000000000 +0000
@@ -0,0 +1,176 @@
+#!perl -T
+
+# =========================================================================== #
+
+use Test::More;
+
+my $js_input = <
+
+
+
+ alert('test');
+
+link
+
+1 < /a>
+
+
+
+
+ < a href="/"> link 2
+ < / a >
+
+
+
+EOT
+
+my $js_expected = 'link 1 link 2 ';
+my $js_expected_html5 = 'link 1 link 2 ';
+my $js_expected_html5_no_js = 'link 1 link 2 ';
+my $js_expected_no_js = 'link 1 link 2 ';
+
+my $css_input = <
+
+ foo {
+ asdf:asdf;
+ ew:12;
+ }
+
+
+link
+
+1 < /a>
+
+
+
+
+ < a href="/"> link 2
+ < / a >
+
+
+EOT
+
+my $css_expected = 'link 1 link 2 ';
+my $css_expected_no_css = 'link 1 link 2 ';
+
+my $html_input = </**/
+
+
+link
+
+1 < /a>
+
+
+
+
+ < a href="/"> link 2
+ < / a >
+
+EOT
+
+my $html_expected = '
link 1 link 2 ';
+my $html_expected_no_js = '
link 1 link 2 ';
+
+my $not = 10;
+
+SKIP: {
+ eval { use HTML::Packer; };
+
+ skip( 'HTML::Packer not installed!', $not ) if ( $@ );
+
+ plan tests => $not;
+
+ minTest( 's1', undef, 'Test without opts.' );
+ minTest( 's2', { remove_newlines => 1 }, 'Test remove_newlines.' );
+ minTest( 's3', { remove_comments => 1 }, 'Test remove_comments.' );
+ minTest( 's4', { remove_comments => 1, remove_newlines => 1 }, 'Test remove_newlines and remove_comments.' );
+ minTest( 's5', { remove_comments => 1, remove_newlines => 1 }, 'Test _no_compress_ comment.' );
+ minTest( 's6', { remove_comments => 1, remove_newlines => 1, no_compress_comment => 1 }, 'Test _no_compress_ comment with no_compress_comment option.' );
+
+ my $packer = HTML::Packer->init();
+ my $js_comp_input = $js_input;
+ my $js_html5_input = $js_input;
+ $packer->minify( \$js_comp_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean' } );
+ $packer->minify( \$js_html5_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean', html5 => 1 } );
+ $packer->minify( \$html_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean', html5 => 1 } );
+
+ eval "use JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER;";
+ if ( $@ ) {
+ is( $js_comp_input, $js_expected_no_js, 'Test do_javascript. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' );
+ is( $js_html5_input, $js_expected_html5_no_js, 'Test do_javascript 2. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' );
+ is( $html_input, $html_expected_no_js, 'Test do_javascript 3. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' );
+ }
+ else {
+ is( $js_comp_input, $js_expected, 'Test do_javascript. JavaScript::Packer installed.' );
+ is( $js_html5_input, $js_expected_html5, 'Test do_javascript 2. JavaScript::Packer installed.' );
+ is( $html_input, $html_expected, 'Test do_javascript 3. JavaScript::Packer installed.' );
+ }
+
+ $packer->minify( \$css_input, { remove_comments => 1, remove_newlines => 1, do_stylesheet => 'pretty' } );
+
+ eval "use CSS::Packer $HTML::Packer::REQUIRED_CSS_PACKER;";
+ if ( $@ ) {
+ is( $css_input, $css_expected_no_css, 'Test do_stylesheet. CSS::Packer >= ' . $HTML::Packer::REQUIRED_CSS_PACKER . ' not installed.' );
+ }
+ else {
+ is( $css_input, $css_expected, 'Test do_stylesheet. CSS::Packer installed.' );
+ }
+}
+
+sub filesMatch {
+ my $file1 = shift;
+ my $file2 = shift;
+ my $a;
+ my $b;
+
+ while (1) {
+ $a = getc($file1);
+ $b = getc($file2);
+
+ if (!defined($a) && !defined($b)) { # both files end at same place
+ return 1;
+ }
+ elsif (
+ !defined($b) || # file2 ends first
+ !defined($a) || # file1 ends first
+ $a ne $b
+ ) { # a and b not the same
+ return 0;
+ }
+ }
+}
+
+sub minTest {
+ my $filename = shift;
+ my $opts = shift || {};
+ my $message = shift || '';
+
+ open(INFILE, 't/html/' . $filename . '.html') or die("couldn't open file");
+ open(GOTFILE, '>t/html/' . $filename . '-got.html') or die("couldn't open file");
+
+ my $html = join( '', );
+
+ my $packer = HTML::Packer->init();
+
+ $packer->minify( \$html, $opts );
+ print GOTFILE $html;
+ close(INFILE);
+ close(GOTFILE);
+
+ open(EXPECTEDFILE, 't/html/' . $filename . '-expected.html') or die("couldn't open file");
+ open(GOTFILE, 't/html/' . $filename . '-got.html') or die("couldn't open file");
+ ok(filesMatch(GOTFILE, EXPECTEDFILE), $message );
+ close(EXPECTEDFILE);
+ close(GOTFILE);
+}
+