Skip Menu |

This queue is for tickets about the CSS-Squish CPAN distribution.

Report information
The Basics
Id: 70800
Status: resolved
Priority: 0/
Queue: CSS-Squish

People
Owner: Nobody in particular
Requestors: SPACEBAT [...] cpan.org
tsibley [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.10
Fixed in: (no value)



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;
Subject: Re: [CSS-Squish #70800] Comments not skipped (patch included)
Date: Thu, 08 Sep 2011 10:04:18 -0400
To: bug-CSS-Squish [...] rt.cpan.org
From: Thomas Sibley <tsibley [...] cpan.org>
On 09/08/2011 03:14 AM, Andrew Kirkpatrick via RT wrote: Show quoted text
> 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.
I'm not really thrilled by the way this is implemented. I think I'd rather see a subclass that filtered at the file_handle (or similar) level and kept the core logic the same. Regardless of how it's implemented, it needs good tests too. Show quoted text
> 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).
I don't really care for perlcritic and don't see a great need to change the return values. This change should really be a separate commit anyway. Cheers, Thomas
Implemented skipping comments [1], but it's different patch. Can you test it? I'm going to ignore "return undef;" vs. "return;" part. It's backwards incompatible change. https://github.com/bestpractical/css- squish/commit/0d09a4adcc0b1c3545e212798bd22f4851546c99 -- Best regards, Ruslan.
On Thu Sep 08 10:07:42 2011, RUZ wrote: Show quoted text
> Implemented skipping comments [1], but it's different patch. Can you > test it?
Hi Ruslan, it tests out fine for me. Show quoted text
> I'm going to ignore "return undef;" vs. "return;" part. It's backwards > incompatible change.
Fair enough. Your patch is much better too. Cheers, Andy