r75254 - in /trunk/libhtml-packer-perl: ./ debian/ inc/Module/ inc/Module/Install/ lib/HTML/ t/

jotamjr-guest at users.alioth.debian.org jotamjr-guest at users.alioth.debian.org
Wed Jun 8 05:39:08 UTC 2011


Author: jotamjr-guest
Date: Wed Jun  8 05:38:52 2011
New Revision: 75254

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75254
Log:
New upstream release

Added:
    trunk/libhtml-packer-perl/META.yml
      - copied unchanged from r75253, branches/upstream/libhtml-packer-perl/current/META.yml
    trunk/libhtml-packer-perl/t/01-interface.t
      - copied unchanged from r75253, branches/upstream/libhtml-packer-perl/current/t/01-interface.t
    trunk/libhtml-packer-perl/t/02-io.t
      - copied unchanged from r75253, branches/upstream/libhtml-packer-perl/current/t/02-io.t
Removed:
    trunk/libhtml-packer-perl/t/01-io.t
Modified:
    trunk/libhtml-packer-perl/Changes
    trunk/libhtml-packer-perl/MANIFEST
    trunk/libhtml-packer-perl/Makefile.PL
    trunk/libhtml-packer-perl/README
    trunk/libhtml-packer-perl/debian/changelog
    trunk/libhtml-packer-perl/inc/Module/Install.pm
    trunk/libhtml-packer-perl/inc/Module/Install/AutoInstall.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Base.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Can.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Fetch.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Include.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Makefile.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Metadata.pm
    trunk/libhtml-packer-perl/inc/Module/Install/Win32.pm
    trunk/libhtml-packer-perl/inc/Module/Install/WriteAll.pm
    trunk/libhtml-packer-perl/lib/HTML/Packer.pm

Modified: trunk/libhtml-packer-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/Changes?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/Changes (original)
+++ trunk/libhtml-packer-perl/Changes Wed Jun  8 05:38:52 2011
@@ -1,4 +1,23 @@
 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.
@@ -6,7 +25,7 @@
     - 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.

Modified: trunk/libhtml-packer-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/MANIFEST?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/MANIFEST (original)
+++ trunk/libhtml-packer-perl/MANIFEST Wed Jun  8 05:38:52 2011
@@ -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

Modified: trunk/libhtml-packer-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/Makefile.PL?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/Makefile.PL (original)
+++ trunk/libhtml-packer-perl/Makefile.PL Wed Jun  8 05:38:52 2011
@@ -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';
 

Modified: trunk/libhtml-packer-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/README?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/README (original)
+++ trunk/libhtml-packer-perl/README Wed Jun  8 05:38:52 2011
@@ -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
 

Modified: trunk/libhtml-packer-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/debian/changelog?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/debian/changelog (original)
+++ trunk/libhtml-packer-perl/debian/changelog Wed Jun  8 05:38:52 2011
@@ -1,3 +1,9 @@
+libhtml-packer-perl (1.002-1) UNRELEASED; urgency=low
+
+  * New upstream release
+
+ -- Jotam Jr. Trejo <jotamjr at debian.org.sv>  Tue, 07 Jun 2011 23:34:33 -0600
+
 libhtml-packer-perl (1.000-1) unstable; urgency=low
 
   [ gregor herrmann ]

Modified: trunk/libhtml-packer-perl/inc/Module/Install.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install.pm Wed Jun  8 05:38:52 2011
@@ -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.

Modified: trunk/libhtml-packer-perl/inc/Module/Install/AutoInstall.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/AutoInstall.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/AutoInstall.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/AutoInstall.pm Wed Jun  8 05:38:52 2011
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Base.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Base.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Base.pm Wed Jun  8 05:38:52 2011
@@ -4,7 +4,7 @@
 use strict 'vars';
 use vars qw{$VERSION};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 }
 
 # Suspend handler for "redefined" warnings

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Can.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Can.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Can.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Can.pm Wed Jun  8 05:38:52 2011
@@ -9,7 +9,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Fetch.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Fetch.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Fetch.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Fetch.pm Wed Jun  8 05:38:52 2011
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Include.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Include.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Include.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Include.pm Wed Jun  8 05:38:52 2011
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Makefile.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Makefile.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Makefile.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Makefile.pm Wed Jun  8 05:38:52 2011
@@ -8,7 +8,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Metadata.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Metadata.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Metadata.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Metadata.pm Wed Jun  8 05:38:52 2011
@@ -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}=();

Modified: trunk/libhtml-packer-perl/inc/Module/Install/Win32.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/Win32.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/Win32.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/Win32.pm Wed Jun  8 05:38:52 2011
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/inc/Module/Install/WriteAll.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/inc/Module/Install/WriteAll.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/inc/Module/Install/WriteAll.pm (original)
+++ trunk/libhtml-packer-perl/inc/Module/Install/WriteAll.pm Wed Jun  8 05:38:52 2011
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.00';
+	$VERSION = '1.01';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }

Modified: trunk/libhtml-packer-perl/lib/HTML/Packer.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-packer-perl/lib/HTML/Packer.pm?rev=75254&op=diff
==============================================================================
--- trunk/libhtml-packer-perl/lib/HTML/Packer.pm (original)
+++ trunk/libhtml-packer-perl/lib/HTML/Packer.pm Wed Jun  8 05:38:52 2011
@@ -8,12 +8,30 @@
 
 # -----------------------------------------------------------------------------
 
-our $VERSION = '1.000';
-
-our @TAGS = (
+our $VERSION = '1.002';
+
+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
@@ -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" : ''
                     )
                 ) : '<!--~' . $_[0]->{store_index} . '~-->';
             },
             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 = '/*<![CDATA[*/' . $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,18 +269,26 @@
         }
     ];
 
+    $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->{global}->{reggrp} = Regexp::RegGrp->new(
+        $self->{ '_reggrp_' . $_ } = Regexp::RegGrp->new( { reggrp => $self->{$_}->{reggrp_data} } );
+    } @REGGRPS;
+
+    $self->{ '_reggrp_' . $GLOBAL_REGGRP } = Regexp::RegGrp->new(
         {
-            reggrp          => $self->{global}->{reggrp_data},
+            reggrp          => $self->{$GLOBAL_REGGRP}->{reggrp_data},
             restore_pattern => qr/<!--~(\d+)~-->/
         }
     );
-
-    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} : '';
-
-        $opts->{no_compress_comment}    = $opts->{no_compress_comment} ? 1 : 0;
-        $opts->{no_cdata}               = $opts->{no_cdata} ? 1 : 0;
-    }
-
-    if ( not $opts->{no_compress_comment} and ${$html} =~ /$PACKER_COMMENT/s ) {
+    if ( ref( $opts ) eq 'HASH' ) {
+        foreach my $field ( @BOOLEAN_ACCESSORS ) {
+            $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) );
+        }
+
+        $self->do_javascript( $opts->{do_javascript} ) if ( defined( $opts->{do_javascript} ) );
+        $self->do_stylesheet( $opts->{do_stylesheet} ) if ( defined( $opts->{do_stylesheet} ) );
+    }
+
+    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->{global}->{reggrp}->restore_stored( $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->reggrp_global()->restore_stored( $html );
 
     return ${$html} if ( $cont eq 'scalar' );
 }
 
-sub _get_opt {
-    my ( $opts_hash, $opt ) = @_;
-
-    $opts_hash  ||= {};
-    $opt        ||= '';
-
-    my $ret = '';
-
-    $ret = $opts_hash->{$opt} if ( defined( $opts_hash->{$opt} ) );
-
-    return $ret;
-}
-
-sub _process_wrapper {
-    my ( $self, $reg_name, $in, $opts ) = @_;
-
-    $self->{$reg_name}->{reggrp}->exec( $in, $opts );
+sub javascript_packer {
+    my $self = shift;
+
+    unless ( $self->{_checked_javascript_packer} ) {
+        eval "use JavaScript::Packer $REQUIRED_JAVASCRIPT_PACKER;";
+
+        unless ( $@ ) {
+            $self->{_javascript_packer} = eval {
+                JavaScript::Packer->init();
+            };
+        }
+
+        $self->{_checked_javascript_packer} = 1;
+    }
+
+    return $self->{_javascript_packer};
+}
+
+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;
+    }
+
+    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<JavaScript::Packer> is installed.
 
@@ -403,7 +458,11 @@
 
     <!-- HTML::Packer _no_compress_ -->
 
-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<bug-html-packer at rt.cpan.org>, or through
-the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Packer>.  I will be notified, and then you'll
+Please report any bugs or feature requests through
+the web interface at L<https://github.com/nevesenin/html-packer-perl/issues>. I will be notified, and then you'll
 automatically be notified of progress on your bug as I make changes.
 
 =head1 SUPPORT




More information about the Pkg-perl-cvs-commits mailing list