Subject: | Comments not skipped (patch included) |
There are a bunch of heavily commented CSS files that I'm looking to
squish, so I decided to add comment skipping to CSS::Squish.
Also, perlcritic didn't like that undef is being explicitly returned, so
I changed those to be implicit (so it is also false in list context).
Do what thou wilt with this patch, I'd just prefer to have this
functionality than do without it.
Cheers
Subject: | CSS::Squish-comments.patch |
--- /apps/site_perl/5.8.5/CSS/Squish.pm 2010-11-06 06:02:46.000000000 +1030
+++ /apps/webteam/lib/perl/CSS/Squish.pm 2011-09-08 16:31:59.000000000 +0930
@@ -153,6 +153,17 @@
my $seen = shift || {};
while ( my $line = <$fh> ) {
+
+ # skip comments
+ if ( $line =~ m|^\s*/\*.*\*/\s*$| ) { print $dest $line; next; }
+ if ( my @comments = $line =~ m|(/\*.*?\*/)|g ) {
+ $line =~ s|/\*.*?\*/||g;
+ print $dest join(' ', @comments);
+ }
+ if ( $line =~ s|^(.*\*/)|| ) { print $dest $1; }
+ if ( $line =~ s|(/\*.*)$|| ) { print $dest $1; }
+ if ( $line =~ /^\s*$/ ) { print $dest $line; next; }
+
if ( $line =~ /$AT_IMPORT/o ) {
my $import = $1;
my $media = $2;
@@ -305,7 +316,7 @@
my $file = shift;
my $content = $self->my_prepare_content($file);
- return undef unless defined $content;
+ return unless defined $content;
open my $fh, "<", \$content or warn "Couldn't open handle: $!";
return $fh;
@@ -323,13 +334,13 @@
my $path = $self->resolve_file( $file );
unless ( defined $path ) {
$self->_debug("Couldn't find '$file' in root(s)");
- return undef;
+ return;
}
my $fh;
unless ( open $fh, '<', $path ) {
$self->_debug("Skipping '$file' ($path) due to error: $!");
- return undef;
+ return;
}
return $fh;
}
@@ -349,7 +360,7 @@
$self->_debug("Looking for '$file'");
my @roots = $self->roots;
unless ( @roots ) {
- return undef unless -e $file;
+ return unless -e $file;
return $file;
}
@@ -360,7 +371,7 @@
return $path if -e $path;
}
- return undef;
+ return;
}
=head2 _resolve_file( $file, @roots )
@@ -395,7 +406,7 @@
if ( defined $uri->scheme || defined $uri->authority ) {
$self->_debug("Skipping uri because it's external");
- return undef;
+ return;
}
my $strip_leading_slash = 0;