Skip to content

Commit

Permalink
separate read file and filter file stages
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jul 25, 2015
1 parent b9a849f commit bba5925
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Middleware/Static.pm
Expand Up @@ -67,7 +67,7 @@ sub wrap {
enable 'Assets::FileCached' => (
files => [ map "root$_", @css_files, @less_files ],
extension => 'css',
filter => sub { scalar `lessc -s $_[0]` },
read_file => sub { scalar `lessc -s $_[0]` },
( $tempdir ? ( cache_dir => "$tempdir/assets" ) : () ),
);
}
Expand Down
10 changes: 7 additions & 3 deletions lib/Plack/Middleware/Assets/FileCached.pm
Expand Up @@ -25,7 +25,7 @@ has app => ( is => 'ro', required => 1 );
has wrapped => ( is => 'lazy', init_arg => 0, reader => 'to_app' );

has files => ( is => 'ro', required => 1 );
has filter => (
has read_file => (
is => 'ro',
default => sub {
sub {
Expand All @@ -38,6 +38,7 @@ has filter => (
};
}
);
has filter => (is => 'ro');
has mount => ( is => 'ro', default => '_assets' );

has extension => (
Expand Down Expand Up @@ -107,12 +108,15 @@ sub _build_wrapped {

sub _build__asset_files {
my $self = shift;
my $filter = $self->filter;
my $read_file = $self->read_file;
my @files = @{ $self->files };
my @assets;
my $content = '';
for my $file (@files) {
$content .= $filter->($file);
$content .= $read_file->($file);
}
if (my $filter = $self->filter) {
$content = $filter->($content);
}
my $key = md5_hex($content);
my $file = "$key." . $self->extension;
Expand Down

0 comments on commit bba5925

Please sign in to comment.