r75544 - in /branches/upstream/libcss-packer-perl/current: ./ inc/Module/ inc/Module/Install/ lib/CSS/ t/
jotamjr-guest at users.alioth.debian.org
jotamjr-guest at users.alioth.debian.org
Sun Jun 12 22:35:14 UTC 2011
Author: jotamjr-guest
Date: Sun Jun 12 22:35:00 2011
New Revision: 75544
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75544
Log:
[svn-upgrade] new version libcss-packer-perl (1.002)
Added:
branches/upstream/libcss-packer-perl/current/META.yml
branches/upstream/libcss-packer-perl/current/t/01-interface.t
branches/upstream/libcss-packer-perl/current/t/02-io.t
Removed:
branches/upstream/libcss-packer-perl/current/t/01-io.t
Modified:
branches/upstream/libcss-packer-perl/current/Changes
branches/upstream/libcss-packer-perl/current/MANIFEST
branches/upstream/libcss-packer-perl/current/Makefile.PL
branches/upstream/libcss-packer-perl/current/README
branches/upstream/libcss-packer-perl/current/inc/Module/Install.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/AutoInstall.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Base.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Can.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Fetch.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Include.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Makefile.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Metadata.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/Win32.pm
branches/upstream/libcss-packer-perl/current/inc/Module/Install/WriteAll.pm
branches/upstream/libcss-packer-perl/current/lib/CSS/Packer.pm
Modified: branches/upstream/libcss-packer-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/Changes?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/Changes (original)
+++ branches/upstream/libcss-packer-perl/current/Changes Sun Jun 12 22:35:00 2011
@@ -1,4 +1,19 @@
Revision history for CSS-Packer
+
+1.002 2011-06-07
+ - Raised version number.
+
+1.001_002 2011-05-19
+ - Added "copyright" and "remove_copyright" options. Suggested by Marc S. Brooks.
+ - Updated POD.
+ - Added tests.
+ - Fixed comment regexp.
+
+1.001_001 2011-04-07
+ - Added accessors.
+ - Added tests.
+ - Minor Bugfixes.
+ - Cleanup.
1.000001 2011-02-27
- Changed requirements to Regexp::RegGrp 1.000001 due to "undefined submatches bug" in Regexp::RegGrp.
Modified: branches/upstream/libcss-packer-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/MANIFEST?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/MANIFEST (original)
+++ branches/upstream/libcss-packer-perl/current/MANIFEST Sun Jun 12 22:35:00 2011
@@ -15,9 +15,11 @@
lib/CSS/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/pod.t
t/stylesheets/s1-expected.css
t/stylesheets/s1.css
Added: branches/upstream/libcss-packer-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/META.yml?rev=75544&op=file
==============================================================================
--- branches/upstream/libcss-packer-perl/current/META.yml (added)
+++ branches/upstream/libcss-packer-perl/current/META.yml Sun Jun 12 22:35:00 2011
@@ -1,0 +1,29 @@
+---
+abstract: 'Another CSS minifier'
+author:
+ - 'Merten Falk, C<< <nevesenin at cpan.org> >>'
+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: CSS::Packer
+name: CSS-Packer
+no_index:
+ directory:
+ - inc
+ - t
+requires:
+ Regexp::RegGrp: 1.001_001
+ perl: 5.8.9
+resources:
+ bugtracker: http://github.com/nevesenin/css-packer-perl/issues
+ license: http://dev.perl.org/licenses/
+ repository: http://github.com/nevesenin/css-packer-perl
+version: 1.002
Modified: branches/upstream/libcss-packer-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/Makefile.PL?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/Makefile.PL (original)
+++ branches/upstream/libcss-packer-perl/current/Makefile.PL Sun Jun 12 22:35:00 2011
@@ -5,9 +5,10 @@
all_from 'lib/CSS/Packer.pm';
test_requires 'Test::More' => 0;
-requires 'Regexp::RegGrp' => "1.000001";
+requires 'Regexp::RegGrp' => "1.001_001";
repository 'http://github.com/nevesenin/css-packer-perl';
+bugtracker 'http://github.com/nevesenin/css-packer-perl/issues';
clean_files 't/stylesheets/s?-got.css';
Modified: branches/upstream/libcss-packer-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/README?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/README (original)
+++ branches/upstream/libcss-packer-perl/current/README Sun Jun 12 22:35:00 2011
@@ -17,6 +17,9 @@
perldoc CSS::Packer
You can also look for information at:
+
+ github
+ http://github.com/nevesenin/css-packer-perl
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CSS-Packer
Modified: branches/upstream/libcss-packer-perl/current/inc/Module/Install.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/AutoInstall.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/AutoInstall.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/AutoInstall.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/AutoInstall.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Base.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Base.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Base.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Can.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Can.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Can.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Can.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Fetch.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Fetch.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Fetch.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Fetch.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Include.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Include.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Include.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Include.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Makefile.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Makefile.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Makefile.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Makefile.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Metadata.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Metadata.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Metadata.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Metadata.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/Win32.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/Win32.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/Win32.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/Win32.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/inc/Module/Install/WriteAll.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/inc/Module/Install/WriteAll.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/inc/Module/Install/WriteAll.pm (original)
+++ branches/upstream/libcss-packer-perl/current/inc/Module/Install/WriteAll.pm Sun Jun 12 22:35:00 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: branches/upstream/libcss-packer-perl/current/lib/CSS/Packer.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/lib/CSS/Packer.pm?rev=75544&op=diff
==============================================================================
--- branches/upstream/libcss-packer-perl/current/lib/CSS/Packer.pm (original)
+++ branches/upstream/libcss-packer-perl/current/lib/CSS/Packer.pm Sun Jun 12 22:35:00 2011
@@ -6,7 +6,22 @@
use Carp;
use Regexp::RegGrp;
-our $VERSION = '1.000001';
+our $VERSION = '1.002';
+
+our @COMPRESS = ( 'minify', 'pretty' );
+our $DEFAULT_COMPRESS = 'pretty';
+
+our @BOOLEAN_ACCESSORS = (
+ 'no_compress_comment',
+ 'remove_copyright'
+);
+
+our @COPYRIGHT_ACCESSORS = (
+ 'copyright',
+ 'copyright_comment'
+);
+
+our $COPYRIGHT_COMMENT = '\/\*((?>[^*]|\*[^/])*copyright(?>[^*]|\*[^/])*)\*\/';
our $DICTIONARY = {
'STRING1' => qr~"(?>(?:(?>[^"\\]+)|\\.|\\"|\\\s)*)"~,
@@ -25,17 +40,86 @@
our $DECLARATION = '((?>[^;:]+)):(?<=:)((?>[^;]*))(?:;|\s*$)';
-our $COMMENT = '(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)';
+our $COMMENT = '(\/\*[^*]*\*+([^/][^*]*\*+)*\/)';
our $PACKER_COMMENT = '\/\*\s*CSS::Packer\s*(\w+)\s*\*\/';
our $CHARSET = '^(\@charset)\s+(' . $DICTIONARY->{STRING1} . '|' . $DICTIONARY->{STRING2} . ');';
+our @REGGRPS = ( 'whitespaces', 'url', 'import', 'declaration', 'rule', 'content_value', 'mediarules', 'global' );
+
# --------------------------------------------------------------------------- #
+{
+ no strict 'refs';
+
+ foreach my $reggrp ( @REGGRPS ) {
+ next if defined *{ __PACKAGE__ . '::reggrp_' . $reggrp }{CODE};
+
+ *{ __PACKAGE__ . '::reggrp_' . $reggrp } = sub {
+ my ( $self ) = shift;
+
+ return $self->{ '_reggrp_' . $reggrp };
+ };
+ }
+
+ 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 $field ( @COPYRIGHT_ACCESSORS ) {
+ $field = '_' . $field if ( $field eq 'copyright_comment' );
+ next if defined *{ __PACKAGE__ . '::' . $field }{CODE};
+
+ *{ __PACKAGE__ . '::' . $field} = sub {
+ my ( $self, $value ) = @_;
+
+ if ( defined( $value ) and not ref( $value ) ) {
+ $value =~ s/^\s*|\s*$//gs;
+ $self->{'_' . $field} = $value;
+ }
+
+ my $ret = '';
+
+ if ( $self->{'_' . $field} ) {
+ $ret = '/* ' . $self->{'_' . $field} . ' */' . "\n";
+ }
+
+ return $ret;
+ };
+ }
+}
+
+sub compress {
+ my ( $self, $value ) = @_;
+
+ if ( defined( $value ) ) {
+ if ( grep( $value eq $_, @COMPRESS ) ) {
+ $self->{_compress} = $value;
+ }
+ elsif ( ! $value ) {
+ $self->{_compress} = undef;
+ }
+ }
+
+ $self->{_compress} ||= $DEFAULT_COMPRESS;
+
+ return $self->{_compress};
+}
+
sub init {
- my $class = shift;
+ my $class = shift;
my $self = {};
+
+ bless( $self, $class );
$self->{content_value}->{reggrp_data} = [
{
@@ -81,15 +165,10 @@
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 );
+
+ my $compress = $self->compress();
+
+ $self->reggrp_url()->exec( \$url );
$mediatype =~ s/^\s*|\s*$//gs;
$mediatype =~ s/\s*,\s*/,/gsm;
@@ -106,19 +185,14 @@
my $submatches = $_[0]->{submatches};
my $key = $submatches->[0];
my $value = $submatches->[1];
- my $opts = $_[0]->{opts} || {};
-
- my $compress = _get_opt( $opts, 'compress' );
+
+ my $compress = $self->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 );
+ $self->reggrp_content_value->exec( \$value );
}
else {
$value =~ s/\s*,\s*/,/gsm;
@@ -139,9 +213,8 @@
my $submatches = $_[0]->{submatches};
my $selector = $submatches->[0];
my $declaration = $submatches->[1];
- my $opts = $_[0]->{opts} || {};
-
- my $compress = _get_opt( $opts, 'compress' );
+
+ my $compress = $self->compress();
$selector =~ s/^\s*|\s*$//gs;
$selector =~ s/\s*,\s*/,/gsm;
@@ -149,11 +222,7 @@
$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 );
+ $self->reggrp_declaration()->exec( \$declaration );
my $store = $selector . '{' . ( $compress eq 'pretty' ? "\n" : '' ) . $declaration . '}' .
( $compress eq 'pretty' ? "\n" : '' );
@@ -176,9 +245,10 @@
regexp => $CHARSET,
replacement => sub {
my $submatches = $_[0]->{submatches};
- my $opts = $_[0]->{opts} || {};
-
- return $submatches->[0] . " " . $submatches->[1] . ( $opts->{compress} eq 'pretty' ? "\n" : '' );
+
+ my $compress = $self->compress();
+
+ return $submatches->[0] . " " . $submatches->[1] . ( $compress eq 'pretty' ? "\n" : '' );
}
},
{
@@ -187,18 +257,13 @@
my $submatches = $_[0]->{submatches};
my $mediatype = $submatches->[0];
my $mediarules = $submatches->[1];
- my $opts = $_[0]->{opts} || {};
-
- my $compress = _get_opt( $opts, 'compress' );
+
+ my $compress = $self->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 );
+ $self->reggrp_mediarules()->exec( \$mediarules );
return '@media ' . $mediatype . '{' . ( $compress eq 'pretty' ? "\n" : '' ) .
$mediarules . '}' . ( $compress eq 'pretty' ? "\n" : '' );
@@ -209,14 +274,12 @@
map {
- $self->{$_}->{reggrp} = Regexp::RegGrp->new(
+ $self->{ '_reggrp_' . $_ } = Regexp::RegGrp->new(
{
reggrp => $self->{$_}->{reggrp_data}
}
);
- } ( 'whitespaces', 'url', 'import', 'declaration', 'rule', 'content_value', 'mediarules', 'global' );
-
- bless( $self, $class );
+ } @REGGRPS;
return $self;
}
@@ -256,56 +319,44 @@
$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/ ) {
+ if ( ref( $opts ) eq 'HASH' ) {
+ foreach my $field ( @BOOLEAN_ACCESSORS ) {
+ $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) );
+ }
+
+ foreach my $field ( 'compress', 'copyright' ) {
+ $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) );
+ }
+ }
+
+ my $copyright_comment = '';
+
+ if ( ${$css} =~ /$COPYRIGHT_COMMENT/ism ) {
+ $copyright_comment = $1;
+ }
+ # Resets copyright_comment() if there is no copyright comment
+ $self->_copyright_comment( $copyright_comment );
+
+ if ( not $self->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};
+ $self->compress( $compress );
}
${$css} =~ s/$COMMENT/ /gsm;
- $self->{global}->{reggrp}->exec( $css, $opts );
+ $self->reggrp_global()->exec( $css );
+
+ if ( not $self->remove_copyright() ) {
+ ${$css} = ( $self->copyright() || $self->_copyright_comment() ) . ${$css};
+ }
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__
@@ -316,7 +367,7 @@
=head1 VERSION
-Version 1.000001
+Version 1.002
=head1 DESCRIPTION
@@ -339,7 +390,7 @@
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
+Second argument must be a hashref of options. Possible options are:
=over 4
@@ -370,6 +421,26 @@
a{color:black;}div{width:100px;}
+=item copyright
+
+You can add a copyright notice at the top of the script.
+
+=item remove_copyright
+
+If there is a copyright notice in a comment it will only be removed if this
+option is set to a true value. Otherwise the first comment that contains the
+word "copyright" will be added at the top of the packed script. A copyright
+comment will be overwritten by a copyright notice defined with the copyright
+option.
+
+=item no_compress_comment
+
+If not set to a true value it is allowed to set a CSS comment that
+prevents the input being packed or defines a compression level.
+
+ /* CSS::Packer _no_compress_ */
+ /* CSS::Packer pretty */
+
=back
=head1 AUTHOR
@@ -378,8 +449,8 @@
=head1 BUGS
-Please report any bugs or feature requests to C<bug-css-packer at rt.cpan.org>, or through
-the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CSS-Packer>. I will be notified, and then you'll
+Please report any bugs or feature requests through
+the web interface at L<http://github.com/nevesenin/css-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
Added: branches/upstream/libcss-packer-perl/current/t/01-interface.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/t/01-interface.t?rev=75544&op=file
==============================================================================
--- branches/upstream/libcss-packer-perl/current/t/01-interface.t (added)
+++ branches/upstream/libcss-packer-perl/current/t/01-interface.t Sun Jun 12 22:35:00 2011
@@ -1,0 +1,62 @@
+#!perl -T
+
+use Test::More;
+
+my $not = 18;
+
+SKIP: {
+ eval { use CSS::Packer; };
+
+ skip( 'CSS::Packer not installed!', $not ) if ( $@ );
+
+ plan tests => $not;
+
+ my $packer = CSS::Packer->init();
+
+ ok( ! $packer->no_compress_comment(), 'Default value for no_compress_comment' );
+ ok( ! $packer->remove_copyright(), 'Default value for remove_copyright' );
+ is( $packer->compress(), 'pretty', 'Default value for compress' );
+ is( $packer->copyright(), '', 'Default value for copyright' );
+
+ $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->remove_copyright( 1 );
+ ok( $packer->remove_copyright(), 'Set remove_copyright.' );
+ $packer->remove_copyright( 0 );
+ ok( ! $packer->remove_copyright(), 'Unset remove_copyright.' );
+
+ $packer->compress( 'minify' );
+ is( $packer->compress(), 'minify', 'Set compress to "minify".' );
+ $packer->compress( 'foo' );
+ is( $packer->compress(), 'minify', 'Set compress to "foo" failed.' );
+ $packer->compress( 'pretty' );
+ is( $packer->compress(), 'pretty', 'Setting compress back to "pretty".' );
+
+ $packer->copyright( 'Ich war\'s!' );
+ is( $packer->copyright(), "/* Ich war's! */\n", 'Set copyright' );
+ $packer->copyright( 'Ich war\'s' . "\n" . 'nochmal!' );
+ is( $packer->copyright(), "/* Ich war's\nnochmal! */\n", 'Set copyright' );
+ $packer->copyright( '' );
+ is( $packer->copyright(), '', 'Reset copyright' );
+
+ my $str = '';
+
+ $packer->minify( \$str, {} );
+
+ ok( ! $packer->no_compress_comment(), 'Default value for no_compress_comment is still set.' );
+ is( $packer->compress(), 'pretty', 'Default value for compress is still set.' );
+
+ $packer->minify(
+ \$str,
+ {
+ compress => 'minify',
+ no_compress_comment => 1,
+ }
+ );
+
+ ok( $packer->no_compress_comment(), 'Set no_compress_comment again.' );
+ is( $packer->compress(), 'minify', 'Set compress to "minify" again.' );
+}
Added: branches/upstream/libcss-packer-perl/current/t/02-io.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcss-packer-perl/current/t/02-io.t?rev=75544&op=file
==============================================================================
--- branches/upstream/libcss-packer-perl/current/t/02-io.t (added)
+++ branches/upstream/libcss-packer-perl/current/t/02-io.t Sun Jun 12 22:35:00 2011
@@ -1,0 +1,116 @@
+#!perl -T
+
+# =========================================================================== #
+#
+# All these tests are stolen from CSS::Minifier
+#
+# =========================================================================== #
+
+use Test::More;
+
+my $not = 16;
+
+SKIP: {
+ eval( 'use CSS::Packer' );
+
+ skip( 'CSS::Packer not installed!', $not ) if ( $@ );
+
+ plan tests => $not;
+
+ 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}";
+ $packer->minify( \$var, { 'compress' => 'minify' } );
+ is( $var, 'foo{a:b;}', 'string literal input and ouput (minify)' );
+ $var = "foo {\na : b;\n}";
+ $packer->minify( \$var, { 'compress' => 'pretty' } );
+ is( $var, "foo{\na:b;\n}\n", 'string literal input and ouput (pretty)' );
+ $var = "foo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->minify( \$var, { 'compress' => 'minify' } );
+ is( $var, "foo{border:0;margin:1;padding:0;}", 'string literal input and ouput (minify)' );
+
+ $var = "foo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->compress( 'pretty' );
+ $packer->copyright( 'BSD' );
+ $packer->minify( \$var );
+ is( $var, '/* BSD */' . "\nfoo{\nborder:0;\nmargin:1;\npadding:0;\n}\n", 'copyright option compression level "pretty"' );
+ $packer->compress( 'minify' );
+ $packer->minify( \$var );
+ is( $var, '/* BSD */' . "\n" . 'foo{border:0;margin:1;padding:0;}', 'copyright option compression level "minify"' );
+
+ $packer = CSS::Packer->init();
+
+ $var = "/* Copyright BSD */foo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->minify( \$var, { remove_copyright => 1 } );
+ is( $var, "foo{\nborder:0;\nmargin:1;\npadding:0;\n}\n", 'copyright comment with remove_copyright option');
+
+ $var = "/* Copyright BSD */foo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->minify( \$var, { remove_copyright => 0 } );
+ is( $var, '/* Copyright BSD */' . "\n" . "foo{\nborder:0;\nmargin:1;\npadding:0;\n}\n", 'copyright comment without remove_copyright option');
+
+ $packer = CSS::Packer->init();
+
+ $var = "/* CSS::Packer _no_compress_ */\nfoo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->minify( \$var );
+ is( $var, "/* CSS::Packer _no_compress_ */\nfoo {\nborder:0;\nmargin:1;\npadding:0\n}", '_no_compress_ comment');
+
+ $var = "/* CSS::Packer _no_compress_ */\nfoo {\nborder:0;\nmargin:1;\npadding:0\n}";
+ $packer->minify( \$var, { no_compress_comment => 1 } );
+ is( $var, "foo{\nborder:0;\nmargin:1;\npadding:0;\n}\n", '_no_compress_ comment with no_compress_comment option');
+}
+
+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 || {};
+
+ 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> );
+
+ 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));
+ close(EXPECTEDFILE);
+ close(GOTFILE);
+}
+
More information about the Pkg-perl-cvs-commits
mailing list