r69223 - in /trunk/libcss-packer-perl: ./ debian/ inc/ lib/CSS/ t/ t/stylesheets/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Mon Feb 21 14:37:16 UTC 2011


Author: jawnsy-guest
Date: Mon Feb 21 14:37:04 2011
New Revision: 69223

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

Added:
    trunk/libcss-packer-perl/.gitignore
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/.gitignore
    trunk/libcss-packer-perl/inc/
      - copied from r69222, branches/upstream/libcss-packer-perl/current/inc/
    trunk/libcss-packer-perl/t/stylesheets/s5-expected.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s5-expected.css
    trunk/libcss-packer-perl/t/stylesheets/s5.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s5.css
    trunk/libcss-packer-perl/t/stylesheets/s6-expected.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s6-expected.css
    trunk/libcss-packer-perl/t/stylesheets/s6.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s6.css
    trunk/libcss-packer-perl/t/stylesheets/s7-expected.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s7-expected.css
    trunk/libcss-packer-perl/t/stylesheets/s7.css
      - copied unchanged from r69222, branches/upstream/libcss-packer-perl/current/t/stylesheets/s7.css
Removed:
    trunk/libcss-packer-perl/META.yml
Modified:
    trunk/libcss-packer-perl/.cvsignore
    trunk/libcss-packer-perl/Changes
    trunk/libcss-packer-perl/MANIFEST
    trunk/libcss-packer-perl/Makefile.PL
    trunk/libcss-packer-perl/README
    trunk/libcss-packer-perl/debian/changelog
    trunk/libcss-packer-perl/lib/CSS/Packer.pm
    trunk/libcss-packer-perl/t/01-io.t
    trunk/libcss-packer-perl/t/stylesheets/s2-expected.css
    trunk/libcss-packer-perl/t/stylesheets/s4-expected.css

Modified: trunk/libcss-packer-perl/.cvsignore
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/.cvsignore?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/.cvsignore (original)
+++ trunk/libcss-packer-perl/.cvsignore Mon Feb 21 14:37:04 2011
@@ -1,10 +1,15 @@
-blib*
-Makefile
-Makefile.old
-Build
-_build*
-pm_to_blib*
-*.tar.gz
-.lwpcookies
-CSS-Packer-*
-cover_db
+/blib*
+/Makefile
+/Makefile.old
+/Makefile.bak
+/MANIFEST.bak
+/META.yml
+/MYMETA.yml
+/Build
+/_build*
+/pm_to_blib*
+/*.tar.gz
+/CSS-Packer-*
+/t/stylesheets/*-got.css
+/inc
+.DS_Store

Modified: trunk/libcss-packer-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/Changes?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/Changes (original)
+++ trunk/libcss-packer-perl/Changes Mon Feb 21 14:37:04 2011
@@ -1,7 +1,39 @@
 Revision history for CSS-Packer
 
-0.1	2008-11-18
-	First version, released on an unsuspecting world.
+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.2	2008-12-22
-	- Added support for removing whitespaces before and after commas
+0.0401  2011-01-05
+    - Changed requirements to Regexp::RegGrp 0.04
+
+0.04    2010-12-03
+    - Raised version number.
+
+0.03_05 2010-10-05
+    - Changed required perl version to 5.8.9.
+
+0.03_04 2010-09-23
+    - Added option to define compression level via comment.
+    - Added tests.
+
+0.03_03 2010-09-13
+    - Changed requirements to Regexp::RegGrp 0.0201
+
+0.03_02 2010-09-07
+    - Fixed typo in documentation.
+
+0.03_01 2010-08-22
+    - IE5/Mac backslash hack is no longer supported.
+    - Moved regexp grouping stuff to Regexp::RegGrp.
+    - Switched to Module::Install.
+    - Added testcases.
+    - Added "_no_compress_" comment functionality.
+    - Added object-oriented interface.
+
+0.2 2008-12-22
+    - Added support for removing whitespaces before and after commas.
+
+0.1 2008-11-18
+    First version, released on an unsuspecting world.

Modified: trunk/libcss-packer-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/MANIFEST?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/MANIFEST (original)
+++ trunk/libcss-packer-perl/MANIFEST Mon Feb 21 14:37:04 2011
@@ -1,5 +1,17 @@
 .cvsignore
+.gitignore
 Changes
+inc/Module/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
 lib/CSS/Packer.pm
 Makefile.PL
 MANIFEST
@@ -15,4 +27,9 @@
 t/stylesheets/s3.css
 t/stylesheets/s4-expected.css
 t/stylesheets/s4.css
-META.yml                                 Module meta-data (added by MakeMaker)
+t/stylesheets/s5-expected.css
+t/stylesheets/s5.css
+t/stylesheets/s6-expected.css
+t/stylesheets/s6.css
+t/stylesheets/s7-expected.css
+t/stylesheets/s7.css

Modified: trunk/libcss-packer-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/Makefile.PL?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/Makefile.PL (original)
+++ trunk/libcss-packer-perl/Makefile.PL Mon Feb 21 14:37:04 2011
@@ -1,20 +1,15 @@
-use 5.008;
 use strict;
 use warnings;
-use ExtUtils::MakeMaker;
 
-WriteMakefile(
-    NAME                => 'CSS::Packer',
-    AUTHOR              => 'Merten Falk <nevesenin at cpan.org>',
-    VERSION_FROM        => 'lib/CSS/Packer.pm',
-    ABSTRACT_FROM       => 'lib/CSS/Packer.pm',
-    ($ExtUtils::MakeMaker::VERSION >= 6.3002
-      ? ('LICENSE'=> 'perl')
-      : ()),
-    PL_FILES            => {},
-    PREREQ_PM => {
-        'Test::More' => 0,
-    },
-    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
-    clean               => { FILES => 'CSS-Packer-*' },
-);
+use inc::Module::Install;
+
+all_from        'lib/CSS/Packer.pm';
+test_requires   'Test::More'        => 0;
+requires        'Regexp::RegGrp'    => "1.000";
+
+repository 'http://github.com/nevesenin/css-packer-perl';
+
+clean_files 't/stylesheets/s?-got.css';
+
+auto_install();
+WriteAll();

Modified: trunk/libcss-packer-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/README?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/README (original)
+++ trunk/libcss-packer-perl/README Mon Feb 21 14:37:04 2011
@@ -1,25 +1,13 @@
 CSS-Packer
-
-The README is used to introduce the module and provide instructions on
-how to install the module, any machine dependencies it may have (for
-example C compilers and installed libraries) and any other information
-that should be provided before the module is installed.
-
-A README file is required for CPAN modules since CPAN extracts the README
-file from a module distribution so that people browsing the archive
-can use it to get an idea of the module's uses. It is usually a good idea
-to provide version information here so that people can decide whether
-fixes for the module are worth downloading.
-
 
 INSTALLATION
 
 To install this module, run the following commands:
 
-	perl Makefile.PL
-	make
-	make test
-	make install
+    perl Makefile.PL
+    make
+    make test
+    make install
 
 SUPPORT AND DOCUMENTATION
 
@@ -45,7 +33,7 @@
 
 COPYRIGHT AND LICENCE
 
-Copyright (C) 2008 Merten Falk
+Copyright (C) 2008 - 2011 Merten Falk
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Modified: trunk/libcss-packer-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/debian/changelog?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/debian/changelog (original)
+++ trunk/libcss-packer-perl/debian/changelog Mon Feb 21 14:37:04 2011
@@ -1,9 +1,13 @@
-libcss-packer-perl (0.2-2) UNRELEASED; urgency=low
+libcss-packer-perl (1.000-1) UNRELEASED; urgency=low
 
+  [ gregor herrmann ]
   * debian/control: Changed: (build-)depend on perl instead of perl-
     modules.
 
- -- gregor herrmann <gregoa at debian.org>  Fri, 23 Oct 2009 02:24:27 +0200
+  [ Jonathan Yu ]
+  * New upstream release
+
+ -- Jonathan Yu <jawnsy at cpan.org>  Mon, 21 Feb 2011 10:00:02 -0500
 
 libcss-packer-perl (0.2-1) unstable; urgency=low
 

Modified: trunk/libcss-packer-perl/lib/CSS/Packer.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/lib/CSS/Packer.pm?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/lib/CSS/Packer.pm (original)
+++ trunk/libcss-packer-perl/lib/CSS/Packer.pm Mon Feb 21 14:37:04 2011
@@ -1,224 +1,311 @@
 package CSS::Packer;
 
-use 5.008;
+use 5.008009;
 use warnings;
 use strict;
 use Carp;
-
-use vars qw/$VERSION $RULE $DECLARATION $COMMENT $CHARSET $MEDIA $IMPORT $PLACEHOLDER/;
-
-$VERSION = '0.2';
-
-$RULE = qr/([^{}~;]+)\{([^{}]*)\}/;
-
-$IMPORT = qr/\@import\s+("[^"]+"|'[^']+'|url\(\s*"[^"]+"\s*\)|url\(\s*'[^']+'\s*\)|url\(\s*[^'"]+?\s*\))(.*?);/;
-
-$MEDIA = qr/\@media([^{}]+){((\s*$IMPORT|$RULE)+)\s*}/;
-
-$DECLARATION = qr/((?>[^;:]+)):(?<=:)((?>[^;]*));/;
-
-$COMMENT = qr/(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/;
-
-$CHARSET = qr/^(\@charset)\s+("[^"]*";|'[^']*';)/;
-
-$PLACEHOLDER = qr/(?>[^~]*)(~(iec_start|iec_end|charset|import_\d+|media_\d+|rule_\d+)~)(?>[^~]*)/;
-
-# -----------------------------------------------------------------------------
+use Regexp::RegGrp;
+
+our $VERSION        = '1.000';
+
+our $DICTIONARY     = {
+    'STRING1'   => qr~"(?>(?:(?>[^"\\]+)|\\.|\\"|\\\s)*)"~,
+    'STRING2'   => qr~'(?>(?:(?>[^'\\]+)|\\.|\\'|\\\s)*)'~
+};
+
+our $WHITESPACES    = '\s+';
+
+our $RULE           = '([^{};]+)\{([^{}]*)\}';
+
+our $URL            = 'url\(\s*(' . $DICTIONARY->{STRING1} . '|' . $DICTIONARY->{STRING2} . '|[^\'"\s]+?)\s*\)';
+
+our $IMPORT         = '\@import\s+(' . $DICTIONARY->{STRING1} . '|' . $DICTIONARY->{STRING2} . '|' . $URL . ')([^;]*);';
+
+our $MEDIA          = '\@media([^{}]+)\{((?:' . $IMPORT . '|' . $RULE . '|' . $WHITESPACES . ')+)\}';
+
+our $DECLARATION    = '((?>[^;:]+)):(?<=:)((?>[^;]*))(?:;|\s*$)';
+
+our $COMMENT        = '(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)';
+
+our $PACKER_COMMENT = '\/\*\s*CSS::Packer\s*(\w+)\s*\*\/';
+
+our $CHARSET        = '^(\@charset)\s+(' . $DICTIONARY->{STRING1} . '|' . $DICTIONARY->{STRING2} . ');';
+
+# --------------------------------------------------------------------------- #
+
+sub init {
+    my $class    = shift;
+    my $self    = {};
+
+    $self->{content_value}->{reggrp_data} = [
+        {
+            regexp      => $DICTIONARY->{STRING1}
+        },
+        {
+            regexp      => $DICTIONARY->{STRING2}
+        },
+        {
+            regexp      => qr~([\w-]+)\(\s*([\w-]+)\s*\)~,
+            replacement => sub {
+                return $_[0]->{submatches}->[0] . '(' . $_[0]->{submatches}->[0] . ')';
+            }
+        },
+        {
+            regexp      => $WHITESPACES,
+            replacement => ''
+        }
+    ];
+
+    $self->{whitespaces}->{reggrp_data} = [
+        {
+            regexp      => $WHITESPACES,
+            replacement => ''
+        }
+    ];
+
+    $self->{url}->{reggrp_data} = [
+        {
+            regexp      => $URL,
+            replacement => sub {
+                my $url  = $_[0]->{submatches}->[0];
+
+                return 'url(' . $url . ')';
+            }
+        }
+    ];
+
+    $self->{import}->{reggrp_data} = [
+        {
+            regexp      => $IMPORT,
+            replacement => sub {
+                my $submatches  = $_[0]->{submatches};
+                my $url         = $submatches->[0];
+                my $mediatype   = $submatches->[2];
+                my $opts        = $_[0]->{opts} || {};
+
+                my $compress    = _get_opt( $opts, 'compress' );
+
+                # I don't like this, but
+                # $self->{url}->{reggrp}->exec( \$url );
+                # will not work. It isn't initialized jet.
+                # If someone has a better idea, please let me know
+                $self->_process_wrapper( 'url', \$url, $opts );
+
+                $mediatype =~ s/^\s*|\s*$//gs;
+                $mediatype =~ s/\s*,\s*/,/gsm;
+
+                return '@import ' . $url . ( $mediatype ? ( ' ' . $mediatype ) : '' ) . ';' . ( $compress eq 'pretty' ? "\n" : '' );
+            }
+        }
+    ];
+
+    $self->{declaration}->{reggrp_data} = [
+        {
+            regexp      => $DECLARATION,
+            replacement => sub {
+                my $submatches  = $_[0]->{submatches};
+                my $key         = $submatches->[0];
+                my $value       = $submatches->[1];
+                my $opts        = $_[0]->{opts} || {};
+
+                my $compress    = _get_opt( $opts, 'compress' );
+
+                $key    =~ s/^\s*|\s*$//gs;
+                $value  =~ s/^\s*|\s*$//gs;
+
+                if ( $key eq 'content' ) {
+                    # I don't like this, but
+                    # $self->{content_value}->{reggrp}->exec( \$value );
+                    # will not work. It isn't initialized jet.
+                    # If someone has a better idea, please let me know
+                    $self->_process_wrapper( 'content_value', \$value, $opts );
+                }
+                else {
+                    $value =~ s/\s*,\s*/,/gsm;
+                    $value =~ s/\s+/ /gsm;
+                }
+
+                return '' if ( not $key or ( not $value and $value ne '0' ) );
+
+                return $key . ':' . $value . ';' . ( $compress eq 'pretty' ? "\n" : '' );
+            }
+        }
+    ];
+
+    $self->{rule}->{reggrp_data} = [
+        {
+            regexp      => $RULE,
+            replacement => sub {
+                my $submatches  = $_[0]->{submatches};
+                my $selector    = $submatches->[0];
+                my $declaration = $submatches->[1];
+                my $opts        = $_[0]->{opts} || {};
+
+                my $compress    = _get_opt( $opts, 'compress' );
+
+                $selector =~ s/^\s*|\s*$//gs;
+                $selector =~ s/\s*,\s*/,/gsm;
+                $selector =~ s/\s+/ /gsm;
+
+                $declaration =~ s/^\s*|\s*$//gs;
+
+                # I don't like this, but
+                # $self->{declaration}->{reggrp}->exec( \$declaration );
+                # will not work. It isn't initialized jet.
+                # If someone has a better idea, please let me know
+                $self->_process_wrapper( 'declaration', \$declaration, $opts );
+
+                my $store = $selector . '{' . ( $compress eq 'pretty' ? "\n" : '' ) . $declaration . '}' .
+                    ( $compress eq 'pretty' ? "\n" : '' );
+
+                $store = '' unless ( $selector or $declaration );
+
+                return $store;
+            }
+        }
+    ];
+
+    $self->{mediarules}->{reggrp_data} = [
+        @{$self->{import}->{reggrp_data}},
+        @{$self->{rule}->{reggrp_data}},
+        @{$self->{whitespaces}->{reggrp_data}}
+    ];
+
+    $self->{global}->{reggrp_data} = [
+        {
+            regexp      => $CHARSET,
+            replacement => sub {
+                my $submatches  = $_[0]->{submatches};
+                my $opts        = $_[0]->{opts} || {};
+
+                return $submatches->[0] . " " . $submatches->[1] . ( $opts->{compress} eq 'pretty' ? "\n" : '' );
+            }
+        },
+        {
+            regexp      => $MEDIA,
+            replacement => sub {
+                my $submatches  = $_[0]->{submatches};
+                my $mediatype   = $submatches->[0];
+                my $mediarules  = $submatches->[1];
+                my $opts        = $_[0]->{opts} || {};
+
+                my $compress    = _get_opt( $opts, 'compress' );
+
+                $mediatype =~ s/^\s*|\s*$//gs;
+                $mediatype =~ s/\s*,\s*/,/gsm;
+
+                # I don't like this, but
+                # $self->{mediarules}->{reggrp}->exec( \$mediarules );
+                # will not work. It isn't initialized jet.
+                # If someone has a better idea, please let me know
+                $self->_process_wrapper( 'mediarules', \$mediarules, $opts );
+
+                return '@media ' . $mediatype . '{' . ( $compress eq 'pretty' ? "\n" : '' ) .
+                    $mediarules . '}' . ( $compress eq 'pretty' ? "\n" : '' );
+            }
+        },
+        @{$self->{mediarules}->{reggrp_data}}
+    ];
+
+
+    map {
+        $self->{$_}->{reggrp} = Regexp::RegGrp->new(
+            {
+                reggrp => $self->{$_}->{reggrp_data}
+            }
+        );
+    } ( 'whitespaces', 'url', 'import', 'declaration', 'rule', 'content_value', 'mediarules', 'global' );
+
+    bless( $self, $class );
+
+    return $self;
+}
 
 sub minify {
-	my ( $scalarref, $opts ) = @_;
-	
-	if ( ref( $scalarref ) ne 'SCALAR' ) {
-		carp( 'First argument must be a scalarref!' );
-		return '';
-	}
-	
-	return '' if ( ${$scalarref} eq '' );
-	
-	if ( ref( $opts ) ne 'HASH' ) {
-		carp( 'Second argument must be a hashref of options! Using defaults!' ) if ( $opts );
-		$opts = { 'compress' => 'pretty' };
-	}
-	else {
-		$opts->{'compress'} = grep( $opts->{'compress'}, ( 'minify', 'pretty' ) ) ? $opts->{'compress'} : 'pretty';
-	}
-	
-	$opts = { 'compress' => 'pretty' } if ( ref( $opts ) ne 'HASH' or $opts->{'compress'} ne 'minify' );
-	
-	${$scalarref} =~ s/~iec_start~/ /gsm;
-	${$scalarref} =~ s/~iec_end~/ /gsm;
-	
-	${$scalarref} =~ s/~charset~/ /gsm;
-	${$scalarref} =~ s/~import_\d+~/ /gsm;
-	${$scalarref} =~ s/~media_\d+~/ /gsm;
-	${$scalarref} =~ s/~rule_\d+~/ /gsm;
- 	${$scalarref} =~ s/\r//gsm;
-	
-	my $charset	= '';
-	my $import	= [];
-	my $media	= [];
-	my $rule	= [];
-	
-	my $_do_declaration = sub {
-		my ( $key, $value ) = @_;
-		
-		$key	=~ s/^\s*|\s*$//gs;
-		$value	=~ s/^\s*|\s*$//gs;
-		
-		if ( $key eq 'content' ) {
-			my @strings;
-			my $_do_content = sub {
-				my $string = shift;
-				
-				my $ret = '~string_' . scalar( @strings ) . '~';
-				
-				push( @strings, $string );
-				
-				return $ret;
-			};
-			
-			$value =~ s/"(\\.|[^"\\])*"/&$_do_content( $& )/egs;
-			
-			$value =~ s/(?>\s+)(~string_\d+~)/$1/gsm;
-			$value =~ s/(~string_\d+~)(?>\s+)/$1/gsm;
-			
-			$value =~ s/~string_(\d+)~/$strings[$1]/egsm;
-		}
-		else {
-			$value =~ s/\s*,\s*/,/gsm;
-			$value =~ s/\s+/ /gsm;
-		}
-		
-		return '' if ( not $key or ( not $value and $value ne '0' ) );
-		
-		return $key . ':' . $value . ';' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' );
-	};
-	
-	my $_do_rule = sub {
-		my ( $selector, $declaration ) = @_;
-		
-		$selector =~ s/^\s*|\s*$//gs;
-		$selector =~ s/\s*,\s*/,/gsm;
-		$selector =~ s/\s+/ /gsm;
-		
-		$declaration =~ s/^\s*|\s*$//gs;
-		
-		$declaration =~ s/$DECLARATION/&$_do_declaration( $1, $2 )/egsm;
-		
-		my $ret = '~rule_' . scalar( @{$rule} ) . '~';
-		
-		my $store = $selector . '{' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' ) . $declaration . '}' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' );
-		
-		$store = '' unless ( $selector or $declaration );
-		
-		push( @{$rule}, $store );
-		
-		return $ret;
-	};
-	
-	my $_do_import = sub {
-		my ( $file, $mediatype ) = @_;
-		
-		if ( $file =~ /^("|')(?>\s*)(.*?)(?>\s*)\1$/ ) {
-			$file = $1 . $2 . $1;
-		}
-		elsif ( $file =~ /^url\(\s*("|')(?>\s*)(.*?)(?>\s*)\1\s*\)$/ ) {
-			$file = 'url(' . $1 . $2 . $1 . ')';
-		}
-		elsif ( $file =~ /^url\((?>\s*)(.*?)(?>\s*)\)$/ ) {
-			$file = 'url(' . $1 . ')';
-		}
-		else {
-			$file = '';
-		}
-		
-		my $store = '@import ' . $file;
-		
-		if ( $mediatype ) {
-			$mediatype =~ s/^\s*|\s*$//gs;
-			$mediatype =~ s/\s*,\s*/,/gsm;
-			
-			$store .= $mediatype;
-		}
-		
-		$store .= ';' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' );
-		
-		my $ret = '~import_' . scalar( @{$import} ) . '~';
-		
-		push( @{$import}, $store );
-		
-		return $ret;
-	};
-	
-	my $iec_isopen = 0;
-	
-	my $_do_comment = sub {
-		my $comment = shift;
-		
-		if ( $comment =~ /\\\*\/$/ and not $iec_isopen ) {
-			$iec_isopen = 1;
-			return '~iec_start~';
-		}
-		elsif ( $comment !~ /\\\*\/$/ and $iec_isopen ) {
-			$iec_isopen = 0;
-			return '~iec_end~';
-		}
-		
-		return ' ';
-	};
-	
-	my $_do_charset = sub {
-		my ( $selector, $declaration ) = @_;
-		
-		$charset = $selector . " " . $declaration . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' );
-		
-		return '~charset~';
-	};
-	
-	my $_do_media = sub {
-		my ( $mediatype, $mediarules ) = @_;
-		
-		$mediatype =~ s/^\s*|\s*$//gs;
-		$mediatype =~ s/\s*,\s*/,/gsm;
-		
-		$mediarules =~ s/$IMPORT/&$_do_import( $1, $2 )/egsm;
-		$mediarules =~ s/$RULE/&$_do_rule( $1, $2 )/egsm;
-		
-		$mediarules =~ s/$PLACEHOLDER/$1/gsm;
-		
-		my $ret = '~media_' . scalar( @{$media} ) . '~';
-		
-		my $store = '@media ' . $mediatype . '{' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' ) .
-			$mediarules . '}' . ( $opts->{'compress'} eq 'pretty' ? "\n" : '' );
-		
-		push( @{$media}, $store );
-		
-		return $ret;
-	};
-	
-	${$scalarref} =~ s/$CHARSET/&$_do_charset( $1, $2 )/emos;
-	
-	${$scalarref} =~ s/$COMMENT/&$_do_comment( $& )/egsm;
-	
-	${$scalarref} =~ s/$MEDIA/&$_do_media( $1, $2 )/egsm;
-	
-	${$scalarref} =~ s/$IMPORT/&$_do_import( $1, $2 )/egsm;
-	
-	${$scalarref} =~ s/$RULE/&$_do_rule( $1, $2 )/egsm;
-	
-	${$scalarref} =~ s/$PLACEHOLDER/$1/gsm;
-	
-	${$scalarref} =~ s/~media_(\d+)~/$media->[$1]/egsm;
-	${$scalarref} =~ s/~rule_(\d+)~/$rule->[$1]/egsm;
-	${$scalarref} =~ s/~import_(\d+)~/$import->[$1]/egsm;
-	${$scalarref} =~ s/~charset~/$charset/gsm;
-	
-	${$scalarref} =~ s/~iec_start~/sprintf( '\/*\\*\/%s', $opts->{'compress'} eq 'pretty' ? "\n" : '' )/egsm;
-	${$scalarref} =~ s/~iec_end~/sprintf( '\/**\/%s', $opts->{'compress'} eq 'pretty' ? "\n" : '' )/egsm;
-	
-	${$scalarref} =~ s/\n$//s unless ( $opts->{'compress'} eq 'pretty' );
+    my ( $self, $input, $opts );
+
+    unless (
+        ref( $_[0] ) and
+        ref( $_[0] ) eq __PACKAGE__
+    ) {
+        $self = __PACKAGE__->init();
+
+        shift( @_ ) unless ( ref( $_[0] ) );
+
+        ( $input, $opts ) = @_;
+    }
+    else {
+        ( $self, $input, $opts ) = @_;
+    }
+
+    if ( ref( $input ) ne 'SCALAR' ) {
+        carp( 'First argument must be a scalarref!' );
+        return undef;
+    }
+
+    my $css     = \'';
+    my $cont    = 'void';
+
+    if ( defined( wantarray ) ) {
+        my $tmp_input = ref( $input ) ? ${$input} : $input;
+
+        $css    = \$tmp_input;
+        $cont   = 'scalar';
+    }
+    else {
+        $css = ref( $input ) ? $input : \$input;
+    }
+
+    if ( ref( $opts ) ne 'HASH' ) {
+        carp( 'Second argument must be a hashref of options! Using defaults!' ) if ( $opts );
+        $opts = { compress => 'pretty', no_compress_comment => 0 };
+    }
+    else {
+        $opts->{compress}               = grep( $opts->{compress}, ( 'minify', 'pretty' ) ) ? $opts->{compress} : 'pretty';
+        $opts->{no_compress_comment}    = $opts->{no_compress_comment} ? 1 : 0;
+    }
+
+    if ( not $opts->{no_compress_comment} and ${$css} =~ /$PACKER_COMMENT/ ) {
+        my $compress = $1;
+        if ( $compress eq '_no_compress_' ) {
+            return ( $cont eq 'scalar' ) ? ${$css} : undef;
+        }
+
+        $opts->{compress} = grep( $compress, ( 'minify', 'pretty' ) ) ? $compress : $opts->{compress};
+    }
+
+    ${$css} =~ s/$COMMENT/ /gsm;
+
+    $self->{global}->{reggrp}->exec( $css, $opts );
+
+    return ${$css} if ( $cont eq 'scalar' );
 }
 
+sub _process_wrapper {
+    my ( $self, $reg_name, $in, $opts ) = @_;
+
+    $self->{$reg_name}->{reggrp}->exec( $in, $opts );
+}
+
+sub _restore_wrapper {
+    my ( $self, $reg_name, $in ) = @_;
+
+    $self->{$reg_name}->{reggrp}->restore_stored( $in );
+}
+
+sub _get_opt {
+    my ( $opts_hash, $opt ) = @_;
+
+    $opts_hash  ||= {};
+    $opt       ||= '';
+
+    my $ret = '';
+
+    $ret = $opts_hash->{$opt} if ( defined( $opts_hash->{$opt} ) );
+
+    return $ret;
+}
+
 1;
 
 __END__
@@ -229,21 +316,27 @@
 
 =head1 VERSION
 
-Version 0.2
+Version 1.000
+
+=head1 DESCRIPTION
+
+A fast pure Perl CSS minifier.
 
 =head1 SYNOPSIS
 
     use CSS::Packer;
 
+    my $packer = CSS::Packer->init();
+
+    $packer->minify( $scalarref, $opts );
+
+To return a scalar without changing the input simply use (e.g. example 2):
+
+    my $ret = $packer->minify( $scalarref, $opts );
+
+For backward compatibility it is still possible to call 'minify' as a function:
+
     CSS::Packer::minify( $scalarref, $opts );
-
-=head1 DESCRIPTION
-
-A fast pure Perl CSS minifier.
-
-=head1 FUNCTIONS
-
-=head2 CSS::Packer::minify( $scalarref, $opts );
 
 First argument must be a scalarref of CSS-Code.
 Second argument must be a hashref of options. The only option is
@@ -260,7 +353,7 @@
     a {
     color:          black
     ;}   div
-    
+
     { width:100px;
     }
 
@@ -297,7 +390,7 @@
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2008 Merten Falk, all rights reserved.
+Copyright 2008 - 2011 Merten Falk, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Modified: trunk/libcss-packer-perl/t/01-io.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/t/01-io.t?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/t/01-io.t (original)
+++ trunk/libcss-packer-perl/t/01-io.t Mon Feb 21 14:37:04 2011
@@ -8,25 +8,30 @@
 
 use Test::More;
 
-my $not = 6;
+my $not = 9;
 
 SKIP: {
 	eval( 'use CSS::Packer' );
-	
+
 	skip( 'CSS::Packer not installed!', $not ) if ( $@ );
-	
+
 	plan tests => $not;
-	
-	minTest( 's1', 'pretty' );
-	minTest( 's2', 'pretty' );
-	minTest( 's3', 'minify' );
-	minTest( 's4', 'minify' );
-	
+
+	minTest( 's1', { compress => 'pretty' } );
+	minTest( 's2', { compress => 'pretty' } );
+	minTest( 's3', { compress => 'minify' } );
+	minTest( 's4', { compress => 'minify' } );
+	minTest( 's5', { compress => 'minify' } );
+	minTest( 's6', { compress => 'minify' } );
+	minTest( 's7', { compress => 'minify', no_compress_comment => 1 } );
+
+	my $packer = CSS::Packer->init();
+
 	my $var = "foo {\na : b;\n}";
-	CSS::Packer::minify( \$var, { 'compress' => 'minify' } );
+	$packer->minify( \$var, { 'compress' => 'minify' } );
 	is( $var, 'foo{a:b;}', 'string literal input and ouput (minify)' );
 	$var = "foo {\na : b;\n}";
-	CSS::Packer::minify( \$var, { 'compress' => 'pretty' } );
+	$packer->minify( \$var, { 'compress' => 'pretty' } );
 	is( $var, "foo{\na:b;\n}\n", 'string literal input and ouput (pretty)' );
 }
 
@@ -35,11 +40,11 @@
 	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;
 		}
@@ -54,18 +59,22 @@
 }
 
 sub minTest {
-	my $filename = shift;
-	my $compress = shift || 'pretty';
-	
+	my $filename    = shift;
+	my $opts        = shift || {};
+
 	open(INFILE, 't/stylesheets/' . $filename . '.css') or die("couldn't open file");
 	open(GOTFILE, '>t/stylesheets/' . $filename . '-got.css') or die("couldn't open file");
-	
+
 	my $css = join( '', <INFILE> );
-	CSS::Packer::minify( \$css, { 'compress' => $compress } );
+
+	my $packer = CSS::Packer->init();
+
+	$packer->minify( \$css, $opts );
+
 	print GOTFILE $css;
 	close(INFILE);
 	close(GOTFILE);
-	
+
 	open(EXPECTEDFILE, 't/stylesheets/' . $filename . '-expected.css') or die("couldn't open file");
 	open(GOTFILE, 't/stylesheets/' . $filename . '-got.css') or die("couldn't open file");
 	ok(filesMatch(GOTFILE, EXPECTEDFILE));

Modified: trunk/libcss-packer-perl/t/stylesheets/s2-expected.css
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/t/stylesheets/s2-expected.css?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/t/stylesheets/s2-expected.css (original)
+++ trunk/libcss-packer-perl/t/stylesheets/s2-expected.css Mon Feb 21 14:37:04 2011
@@ -8,11 +8,9 @@
 .clearfix{
 display:inline-block;
 }
-/*\*/
 * html .clearfix{
 height:1%;
 }
 .clearfix{
 display:block;
 }
-/**/

Modified: trunk/libcss-packer-perl/t/stylesheets/s4-expected.css
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcss-packer-perl/t/stylesheets/s4-expected.css?rev=69223&op=diff
==============================================================================
--- trunk/libcss-packer-perl/t/stylesheets/s4-expected.css (original)
+++ trunk/libcss-packer-perl/t/stylesheets/s4-expected.css Mon Feb 21 14:37:04 2011
@@ -1,1 +1,1 @@
-.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.clearfix{display:inline-block;}/*\*/* html .clearfix{height:1%;}.clearfix{display:block;}/**/
+.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.clearfix{display:inline-block;}* html .clearfix{height:1%;}.clearfix{display:block;}




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