Hello community,

here is the log from the commit of package perl-Mojolicious-Plugin-AssetPack 
for openSUSE:Factory checked in at 2015-04-22 01:18:40
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Mojolicious-Plugin-AssetPack (Old)
 and      /work/SRC/openSUSE:Factory/.perl-Mojolicious-Plugin-AssetPack.new 
(New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "perl-Mojolicious-Plugin-AssetPack"

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/perl-Mojolicious-Plugin-AssetPack/perl-Mojolicious-Plugin-AssetPack.changes
      2015-04-18 10:40:02.000000000 +0200
+++ 
/work/SRC/openSUSE:Factory/.perl-Mojolicious-Plugin-AssetPack.new/perl-Mojolicious-Plugin-AssetPack.changes
 2015-04-22 01:18:41.000000000 +0200
@@ -1,0 +2,12 @@
+Mon Apr 20 08:53:27 UTC 2015 - [email protected]
+
+- updated to 0.5201
+   see /usr/share/doc/packages/perl-Mojolicious-Plugin-AssetPack/Changes
+
+-------------------------------------------------------------------
+Sun Apr 19 07:07:13 UTC 2015 - [email protected]
+
+- updated to 0.52
+   see /usr/share/doc/packages/perl-Mojolicious-Plugin-AssetPack/Changes
+
+-------------------------------------------------------------------

Old:
----
  Mojolicious-Plugin-AssetPack-0.51.tar.gz

New:
----
  Mojolicious-Plugin-AssetPack-0.5201.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ perl-Mojolicious-Plugin-AssetPack.spec ++++++
--- /var/tmp/diff_new_pack.tYN2GR/_old  2015-04-22 01:18:42.000000000 +0200
+++ /var/tmp/diff_new_pack.tYN2GR/_new  2015-04-22 01:18:42.000000000 +0200
@@ -17,7 +17,7 @@
 
 
 Name:           perl-Mojolicious-Plugin-AssetPack
-Version:        0.51
+Version:        0.5201
 Release:        0
 %define cpan_name Mojolicious-Plugin-AssetPack
 Summary:        Compress and convert css, less, sass, javascript and 
coffeescript files

++++++ Mojolicious-Plugin-AssetPack-0.51.tar.gz -> 
Mojolicious-Plugin-AssetPack-0.5201.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/Changes 
new/Mojolicious-Plugin-AssetPack-0.5201/Changes
--- old/Mojolicious-Plugin-AssetPack-0.51/Changes       2015-04-16 
08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/Changes     2015-04-20 
08:48:47.000000000 +0200
@@ -1,7 +1,18 @@
 Revision history for perl distribution Mojolicious-Plugin-AssetPack
 
-0.51 2015-04-16T08:15:50+0200
+0.5201 2015-04-20T08:48:47+0200
+
+ - Fix sprites.t
+ - Fix skipping t/plugin-with-assets.t
 
+0.52 2015-04-18T12:54:40+0200
+ - Add support for generating image sprites and css
+ - Add EXPERIMENTAL ::Handlers::Sprites, ::Handlers::Http and ::Handlers::Https
+ - Add ::Asset::content()
+ - Rename ::Asset::url() to path().
+ - Remove ::Asset::add_chunk()
+
+0.51 2015-04-16T08:15:50+0200
  - Can reload assets on server reload (EXPERIMENTAL)
 
 0.50 2015-04-13T11:37:08Z +0200
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/MANIFEST 
new/Mojolicious-Plugin-AssetPack-0.5201/MANIFEST
--- old/Mojolicious-Plugin-AssetPack-0.51/MANIFEST      2015-04-16 
08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/MANIFEST    2015-04-20 
08:48:48.000000000 +0200
@@ -4,8 +4,12 @@
 Changes
 cpanfile
 examples/reloader.pl
+examples/sprites.pl
 lib/Mojolicious/Plugin/AssetPack.pm
 lib/Mojolicious/Plugin/AssetPack/Asset.pm
+lib/Mojolicious/Plugin/AssetPack/Handler/Http.pm
+lib/Mojolicious/Plugin/AssetPack/Handler/Https.pm
+lib/Mojolicious/Plugin/AssetPack/Handler/Sprites.pm
 lib/Mojolicious/Plugin/AssetPack/Manual/Assets.pod
 lib/Mojolicious/Plugin/AssetPack/Manual/Cookbook.pod
 lib/Mojolicious/Plugin/AssetPack/Manual/CustomDomain.pod
@@ -64,6 +68,9 @@
 t/public/css/c.css
 t/public/css/d.css
 t/public/dummy.foo
+t/public/images/xyz/social-chrome.png
+t/public/images/xyz/social-github.png
+t/public/images/xyz/social-rss.png
 t/public/js/a.js
 t/public/js/b.js
 t/public/js/c.coffee
@@ -85,6 +92,7 @@
 t/scss.t
 t/skip-minified.t
 t/SomePluginWithAssets.pm
+t/sprites.t
 t/twice.t
 t/undefined.t
 META.yml                                 Module YAML meta-data (added by 
MakeMaker)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/META.json 
new/Mojolicious-Plugin-AssetPack-0.5201/META.json
--- old/Mojolicious-Plugin-AssetPack-0.51/META.json     2015-04-16 
08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/META.json   2015-04-20 
08:48:48.000000000 +0200
@@ -50,5 +50,5 @@
          "url" : 
"https://github.com/jhthorsen/mojolicious-plugin-assetpack.git";
       }
    },
-   "version" : "0.51"
+   "version" : "0.5201"
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/META.yml 
new/Mojolicious-Plugin-AssetPack-0.5201/META.yml
--- old/Mojolicious-Plugin-AssetPack-0.51/META.yml      2015-04-16 
08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/META.yml    2015-04-20 
08:48:48.000000000 +0200
@@ -27,4 +27,4 @@
   bugtracker: https://github.com/jhthorsen/mojolicious-plugin-assetpack/issues
   homepage: https://github.com/jhthorsen/mojolicious-plugin-assetpack
   repository: https://github.com/jhthorsen/mojolicious-plugin-assetpack.git
-version: '0.51'
+version: '0.5201'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/README 
new/Mojolicious-Plugin-AssetPack-0.5201/README
--- old/Mojolicious-Plugin-AssetPack-0.51/README        2015-04-16 
08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/README      2015-04-20 
08:48:48.000000000 +0200
@@ -3,7 +3,7 @@
     javascript and coffeescript files
 
 VERSION
-    0.51
+    0.5201
 
 SYNOPSIS
   Application
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/examples/sprites.pl 
new/Mojolicious-Plugin-AssetPack-0.5201/examples/sprites.pl
--- old/Mojolicious-Plugin-AssetPack-0.51/examples/sprites.pl   1970-01-01 
01:00:00.000000000 +0100
+++ new/Mojolicious-Plugin-AssetPack-0.5201/examples/sprites.pl 2015-04-18 
12:50:47.000000000 +0200
@@ -0,0 +1,27 @@
+#!perl
+use lib "lib";
+use Mojolicious::Lite;
+app->static->paths([Cwd::abs_path("t/public")]);
+
+plugin "AssetPack";
+app->asset("my-sprites.css" => "sprites:///images/xyz", "/test.css");
+
+get "/" => "index";
+app->start;
+
+__DATA__
+@@ test.css
+.xyz { background-color: #f00; }
+@@ index.html.ep
+<html>
+  <head>
+    <title>Sprites</title>
+    %= asset "my-sprites.css"
+  </head>
+  <body>
+    <a href="https://css-tricks.com/css-sprites/";>CSS sprites</a>
+    <span class="xyz social-github"></span>
+    <span class="xyz social-rss"></span>
+    <span class="xyz social-chrome"></span>
+  </body>
+</html>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Asset.pm 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Asset.pm
--- 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Asset.pm 
    2015-04-15 18:06:18.000000000 +0200
+++ 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Asset.pm
   2015-04-18 12:54:17.000000000 +0200
@@ -21,77 +21,76 @@
 use Cwd            ();
 use Carp           ();
 use File::Basename ();
+use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0;
 
 =head1 ATTRIBUTES
 
+=head2 content
+
+  $self = $self->content($data);
+  $data = $self->content;
+
 =head2 in_memory
 
 Boolean true if this file only exists in memory, false if stored on disk.
 
-=head2 url
+=head2 path
 
-Either location on disk, HTTP URL or a virtual location (in case of 
L</in_memory>).
+Either location on disk or a virtual location.
 
 =cut
 
+has content   => '';
 has in_memory => 1;
-has url       => '';
+has path      => '';
 
 =head1 METHODS
 
-=head2 add_chunk
-
-  $self = $self->add_chunk($bytes);
-
-Will store data internally, which later can be written to disk using L</save>.
-
-=cut
-
-sub add_chunk {
-  my ($self, $chunk) = @_;
-  $self->{content} //= '';
-  $self->{content} .= $chunk;
-  $self;
-}
-
 =head2 basename
 
-Returns the basename of L</url>.
+Returns the basename of L</path>.
 
 =cut
 
-sub basename { File::Basename::basename(shift->url); }
+sub basename { File::Basename::basename(shift->path); }
 
 =head2 slurp
 
   $bytes = $self->slurp;
 
-Read in the contents of the asset. Returns the data from L</add_chunk>
+Read in the contents of the asset. Returns the data from L</content>
 if L</in_memory> is true.
 
 =cut
 
 sub slurp {
   my $self = shift;
-  $self->in_memory ? $self->{content} // '' : Mojo::Util::slurp($self->url);
+  $self->in_memory ? $self->{content} // '' : Mojo::Util::slurp($self->path);
 }
 
 =head2 save
 
   $self = $self->->save;
 
-L</save> is used to write all the L</add_chunk> data to disk.
-
-This method does nothing if L</in_memory> is true.
+L</save> is used to write L</content> to disk. This method does nothing if
+L</in_memory> is true.
 
 =cut
 
 sub save {
   my $self = shift;
 
-  return $self if $self->in_memory;
-  die "Nothing to save to @{[$self->url]}" unless defined $self->{content};
-  Mojo::Util::spurt(delete $self->{content}, $self->url);
+  if (not defined $self->{content}) {
+    die "Cannot save empty asset to save to @{[$self->path]}";
+  }
+  elsif ($self->in_memory) {
+    warn "[ASSETPACK] Skip save of @{[$self->path]}\n" if DEBUG;
+  }
+  else {
+    warn "[ASSETPACK] Save @{[$self->path]}\n" if DEBUG;
+    Mojo::Util::spurt(delete $self->{content}, $self->path);
+  }
+
   return $self;
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Http.pm
 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Http.pm
--- 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Http.pm
      1970-01-01 01:00:00.000000000 +0100
+++ 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Http.pm
    2015-04-18 12:54:17.000000000 +0200
@@ -0,0 +1,61 @@
+package Mojolicious::Plugin::AssetPack::Handler::Http;
+
+=head1 NAME
+
+Mojolicious::Plugin::AssetPack::Handler::Http - A URL handler for http:// 
assets
+
+=head1 DESCRIPTION
+
+L<Mojolicious::Plugin::AssetPack::Handler::Sprites> is a module that can
+fetch assets from web.
+
+This class is EXPERIMENTAL.
+
+=cut
+
+use Mojo::Base -base;
+use Mojolicious::Types;
+use Mojolicious::Plugin::AssetPack::Asset;
+use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0;
+
+=head1 ATTRIBUTES
+
+=head2 asset_for
+
+  $asset = $self->asset_for($url, $assetpack);
+
+This method tries to download the asset from web.
+
+=cut
+
+sub asset_for {
+  my ($self, $url, $assetpack) = @_;
+  my $tx     = $assetpack->_ua->get($url);
+  my $ct     = $tx->res->headers->content_type // 'text/plain';
+  my $lookup = Mojolicious::Plugin::AssetPack::_name($url);
+  my $ext    = Mojolicious::Types->new->detect($ct) || 'txt';
+
+  if (my $e = $tx->error) {
+    die "Asset $url could not be fetched: $e->{message}";
+  }
+
+  $ext = $ext->[0] if ref $ext;
+  $ext = $tx->req->url->path =~ m!\.(\w+)$! ? $1 : 'txt' if !$ext or $ext eq 
'bin';
+  $assetpack->_app->log->info("Asset $url was fetched");
+  $assetpack->_asset("$lookup.$ext")->content($tx->res->body);
+}
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014, Jan Henning Thorsen
+
+This program is free software, you can redistribute it and/or modify it under
+the terms of the Artistic License version 2.0.
+
+=head1 AUTHOR
+
+Jan Henning Thorsen - C<[email protected]>
+
+=cut
+
+1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Https.pm
 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Https.pm
--- 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Https.pm
     1970-01-01 01:00:00.000000000 +0100
+++ 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Https.pm
   2015-04-18 12:54:17.000000000 +0200
@@ -0,0 +1,28 @@
+package Mojolicious::Plugin::AssetPack::Handler::Https;
+
+=head1 NAME
+
+Mojolicious::Plugin::AssetPack::Handler::Https - A URL handler for https:// 
assets
+
+=head1 DESCRIPTION
+
+See L<Mojolicious::Plugin::AssetPack::Handler::Http>.
+
+=cut
+
+use Mojo::Base 'Mojolicious::Plugin::AssetPack::Handler::Http';
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014, Jan Henning Thorsen
+
+This program is free software, you can redistribute it and/or modify it under
+the terms of the Artistic License version 2.0.
+
+=head1 AUTHOR
+
+Jan Henning Thorsen - C<[email protected]>
+
+=cut
+
+1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Sprites.pm
 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Sprites.pm
--- 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack/Handler/Sprites.pm
   1970-01-01 01:00:00.000000000 +0100
+++ 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack/Handler/Sprites.pm
 2015-04-20 08:39:16.000000000 +0200
@@ -0,0 +1,101 @@
+package Mojolicious::Plugin::AssetPack::Handler::Sprites;
+
+=head1 NAME
+
+Mojolicious::Plugin::AssetPack::Handler::Sprites - A URL handler for 
sprites:// assets
+
+=head1 DESCRIPTION
+
+L<Mojolicious::Plugin::AssetPack::Handler::Sprites> is a module that can
+generate sprites from image files in a directory.
+
+This module require L<Imager> and L<Imager::File::PNG> to work. Below you can
+see how to install it on Debian or Ubuntu:
+
+  $ apt-get install libpng12-dev
+  $ cpanm Imager::File::PNG
+
+This class is EXPERIMENTAL.
+
+=cut
+
+use Mojo::Base -base;
+use File::Basename 'basename';
+use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0;
+
+=head1 ATTRIBUTES
+
+=head2 asset_for
+
+  $asset = $self->asset_for($url, $assetpack);
+
+This method finds images in the location specified in the C<$url>, and
+generates a 
L<sprite|http://en.wikipedia.org/wiki/Sprite_%28computer_graphics%29#Sprites_by_CSS>.
+
+The returning C<$asset> contains CSS with classnames describing how to use
+each image. Example with C<$url> set to "sprites:///images/xyz".
+
+  .xyz { background: url(xyz-5200164c30fb8660952969caf0cefa3d.png) no-repeat; 
display: inline-block; }
+  .xyz.social-rss { background-position: 0px -0px; width: 34px; height: 30px; }
+  .xyz.social-github { background-position: 0px -30px; width: 40px; height: 
40px; }
+  .xyz.social-chrome { background-position: 0px -70px; width: 32px; height: 
32px; }
+
+=cut
+
+sub asset_for {
+  my ($self, $url, $assetpack) = @_;
+  my $name  = basename $url->path;
+  my $tiled = $self->_imager(xsize => 1000, ysize => 10000, channels => 4);
+  my $css   = '';
+  my @size  = (0, 0);
+  my ($checksum, $directory);
+
+  for my $static (@{$assetpack->_app->static->paths}) {
+    $directory = File::Spec->catdir($static, $url->path);
+    last if -d $directory;
+  }
+
+  die "Could not find directory for $url" unless $directory;
+  opendir my $SPRITES, $directory or die "opendir $directory: $!";
+
+  for my $file (sort { $a cmp $b } readdir $SPRITES) {
+    next unless $file =~ /\.(jpe?g|png)$/i;
+    my $tile = Imager->new(file => File::Spec->catfile($directory, $file)) or 
die Imager->errstr;
+    my $cn = $file;
+    my ($w, $h) = ($tile->getwidth, $tile->getheight);
+    $cn =~ s!\.\w+$!!;
+    $cn =~ s!\W!-!g;
+    $css .= ".$name.$cn { background-position: 0px -$size[1]px; width: ${w}px; 
height: ${h}px; }\n";
+    warn "[ASSETPACK] Adding $directory/$file to sprite $name.png $w x $h\n" 
if DEBUG;
+    $tiled->paste(src => $tile, left => 0, top => $size[1]) or die 
$tiled->errstr;
+    $size[1] += $h;
+    $size[0] = $w if $size[0] < $w;
+  }
+
+  $tiled->crop(right => $size[0], bottom => $size[1])->write(data => \my 
$sprite, type => 'png') or die $tiled->errstr;
+  $checksum = Mojo::Util::md5_sum($sprite);
+  $css .= ".$name { background: url($name-$checksum.png) no-repeat; display: 
inline-block; }\n";
+  
$assetpack->_asset("$name-$checksum.png")->content($sprite)->in_memory($assetpack->out_dir
 ? 0 : 1)->save;
+  $assetpack->_asset("$name.css")->content($css);
+}
+
+sub _imager {
+  my $self = shift;
+  require Imager::File::PNG;
+  Imager->new(@_);
+}
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014, Jan Henning Thorsen
+
+This program is free software, you can redistribute it and/or modify it under
+the terms of the Artistic License version 2.0.
+
+=head1 AUTHOR
+
+Jan Henning Thorsen - C<[email protected]>
+
+=cut
+
+1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack.pm 
new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack.pm
--- old/Mojolicious-Plugin-AssetPack-0.51/lib/Mojolicious/Plugin/AssetPack.pm   
2015-04-16 08:15:50.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/lib/Mojolicious/Plugin/AssetPack.pm 
2015-04-20 08:48:47.000000000 +0200
@@ -12,9 +12,7 @@
 use constant NO_CACHE => $ENV{MOJO_ASSETPACK_NO_CACHE} || 0;
 use constant DEBUG    => $ENV{MOJO_ASSETPACK_DEBUG}    || 0;
 
-our $VERSION = '0.51';
-
-my $MTIME = time;
+our $VERSION = '0.5201';
 
 has base_url      => '/packed/';
 has minify        => 0;
@@ -37,7 +35,7 @@
 
 sub fetch {
   my $self = shift;
-  $self->_fetch(@_, $self->out_dir)->url;
+  $self->_handler('https')->asset_for(shift, 
$self)->in_memory(!$self->out_dir)->save->path;
 }
 
 sub get {
@@ -106,7 +104,9 @@
 
 sub _asset {
   my ($self, $name) = @_;
-  $self->{asset}{$name} ||= Mojolicious::Plugin::AssetPack::Asset->new(url => 
$name);
+  my $asset = $self->{asset}{$name} ||= 
Mojolicious::Plugin::AssetPack::Asset->new;
+  $asset->path(File::Spec->catfile($self->out_dir, $name)) unless $asset->path;
+  $asset;
 }
 
 sub _assets {
@@ -127,8 +127,8 @@
       return unless $path->[1] and 0 == index "$path", $self->base_url;
       return unless my $asset = $c->asset->_asset($path->[1]);
       return if $asset->{internal};
-      $c->res->headers->last_modified(Mojo::Date->new($MTIME))
-        ->content_type($c->app->types->type($asset->url =~ /\.(\w+)$/ ? $1 : 
'txt') || 'text/plain');
+      $c->res->headers->last_modified(Mojo::Date->new($^T))
+        ->content_type($c->app->types->type($asset->path =~ /\.(\w+)$/ ? $1 : 
'txt') || 'text/plain');
       $c->reply->asset($asset);
     }
   );
@@ -154,32 +154,6 @@
   return $out_dir // '';
 }
 
-sub _fetch {
-  my ($self, $url, $save) = @_;
-  my $lookup = _name($url);
-  my $asset;
-
-  if ($asset = $self->_find('packed', qr{^$lookup\.\w+$})) {
-    $self->_app->log->debug("Asset $url is already downloaded") if DEBUG;
-    return $asset;
-  }
-
-  my $res = $self->_ua->get($url)->res;
-  my $ct  = $res->headers->content_type // 'text/plain';
-  my $ext = Mojolicious::Types->new->detect($ct) || 'txt';
-
-  if (my $e = $res->error) {
-    die "Asset $url could not be fetched: $e->{message}";
-  }
-
-  $ext = $ext->[0] if ref $ext;
-  $ext = Mojo::URL->new($url)->path =~ m!\.(\w+)$! ? $1 : 'txt' if !$ext or 
$ext eq 'bin';
-  $self->_app->log->info("Asset $url was fetched");
-  $asset = $self->_asset("$lookup.$ext")->url($url)->add_chunk($res->body);
-  $asset->in_memory(0)->url(File::Spec->catfile($self->out_dir, 
"$lookup.$ext"))->save if $save;
-  $asset;
-}
-
 sub _find {
   my $needle = pop;
   my $self   = shift;
@@ -191,13 +165,22 @@
   for my $path (map { File::Spec->catdir($_, @path) } 
@{$self->_app->static->paths}) {
     opendir my $DH, $path or next;
     for (readdir $DH) {
-      /$needle/ and return 
$self->_asset($_)->url(Cwd::abs_path(File::Spec->catfile($path, 
$_)))->in_memory(0);
+      /$needle/ and return 
$self->_asset($_)->path(Cwd::abs_path(File::Spec->catfile($path, 
$_)))->in_memory(0);
     }
   }
 
   return undef;
 }
 
+sub _handler {
+  my ($self, $moniker) = @_;
+  $self->{handler}{$moniker} ||= do {
+    my $class = "Mojolicious::Plugin::AssetPack::Handler::" . ucfirst $moniker;
+    eval "require $class;1" or die "Could not load $class: $@\n";
+    $class->new;
+  };
+}
+
 sub _inject {
   my ($self, $c, $moniker, $args, @attrs) = @_;
   my $tag_helper = $moniker =~ /\.js/ ? 'javascript' : 'stylesheet';
@@ -248,8 +231,8 @@
   my ($asset, $file, $re, @checksum);
 
   @sources = map {
-    my $asset = $self->_find(split '/', $_) || (/^https?:/ ? $self->_fetch($_, 
$self->out_dir) : $self->_fetch($_, ''));
-    push @checksum, $self->preprocessors->checksum(_ext($_), \$asset->slurp, 
$asset->url);
+    my $asset = $self->_source_for_url($_);
+    push @checksum, $self->preprocessors->checksum(_ext($_), \$asset->slurp, 
$asset->path);
     $asset;
   } @sources;
 
@@ -263,24 +246,24 @@
   }
 
   $asset = $self->{asset}{$file} = Mojolicious::Plugin::AssetPack::Asset->new;
-  $asset->in_memory(1)->url(File::Spec->catfile($self->out_dir, $file));
+  $asset->in_memory(1)->path(File::Spec->catfile($self->out_dir, $file));
 
   for my $source (@sources) {
     eval {
       my $content = $source->slurp;
-      $self->preprocessors->process(_ext($source->url), $self, \$content, 
$source->url);
-      $asset->add_chunk($content);
+      $self->preprocessors->process(_ext($source->path), $self, \$content, 
$source->path);
+      $asset->content($asset->content . $content);
       1;
     } or do {
       my $e = $@;
-      warn "[ASSETPACK] process(@{[$source->url]}) FAIL $e\n" if DEBUG;
-      $asset->url(File::Spec->catfile($self->out_dir, 
"$name-$checksum[0].err.$ext"));
-      $asset->add_chunk($self->_make_error_asset($moniker, $source->basename, 
$e || 'Unknown error'));
+      warn "[ASSETPACK] process(@{[$source->path]}) FAIL $e\n" if DEBUG;
+      $asset->path(File::Spec->catfile($self->out_dir, 
"$name-$checksum[0].err.$ext"));
+      $asset->content($self->_make_error_asset($moniker, $source->basename, $e 
|| 'Unknown error'));
       last;
     };
   }
 
-  $asset->in_memory($self->out_dir ? 0 : 1)->save;
+  $asset->in_memory(!$self->out_dir)->save;
   $self->_app->log->info("Built asset for $moniker");
   $asset;
 }
@@ -298,7 +281,7 @@
   return if !$config->{enabled} and $app->mode ne 'development';
 
   warn "[ASSETPACK] Adding reloader asset and route\n" if DEBUG;
-  $reloader->url('reloader.js')->{internal} = 1;
+  $reloader->path('reloader.js')->{internal} = 1;
   $self->{assets}{'reloader.js'} = [$reloader];
   push @{$app->renderer->classes}, __PACKAGE__;
   $app->routes->get('/packed/reloader')->to(template => 'packed/reloader', 
strategy => 'document', %$config);
@@ -309,6 +292,28 @@
   )->name('assetpack.ws');
 }
 
+sub _source_for_url {
+  my $self = shift;
+  my $url  = Mojo::URL->new(shift);
+  my $asset;
+
+  if (my $scheme = $url->scheme) {
+    my $lookup = _name($url);
+
+    if ($asset = $self->_find('packed', qr{^$lookup\.\w+$})) {
+      $self->_app->log->debug("Asset $url is fetched") if DEBUG;
+    }
+    else {
+      $asset = $self->_handler($scheme)->asset_for($url, 
$self)->in_memory(!$self->out_dir)->save;
+    }
+  }
+  else {
+    $asset = $self->_find(split '/', $url) || 
$self->_handler('https')->asset_for($url, $self);
+  }
+
+  return $asset;
+}
+
 # utils
 sub _ext { local $_ = File::Basename::basename($_[0]); /\.(\w+)$/ ? $1 : 
'unknown'; }
 
@@ -329,7 +334,7 @@
 
 =head1 VERSION
 
-0.51
+0.5201
 
 =head1 SYNOPSIS
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/Mojolicious-Plugin-AssetPack-0.51/t/plugin-with-assets.t 
new/Mojolicious-Plugin-AssetPack-0.5201/t/plugin-with-assets.t
--- old/Mojolicious-Plugin-AssetPack-0.51/t/plugin-with-assets.t        
2015-04-14 08:06:39.000000000 +0200
+++ new/Mojolicious-Plugin-AssetPack-0.5201/t/plugin-with-assets.t      
2015-04-20 08:45:50.000000000 +0200
@@ -6,23 +6,19 @@
 plan skip_all => 'Something weird is going on with cygwin filesystem', if $^O 
eq 'cygwin';
 
 my @READ_ONLY = qw( t/read-only-with-source-assets 
t/read-only-with-existing-assets );
-my ($assetpack, $t);
 
-{
-  unlink $_ for glob "$READ_ONLY[0]/packed/my-plugin-*.css";
-  mkdir $_  for @READ_ONLY;
-  chmod 0555, $_ for @READ_ONLY;
-  plan skip_all => 'Need unix filesystem' unless 0555 == (0777 & (stat 
$READ_ONLY[0])[2]);
-}
+unlink $_ for glob "$READ_ONLY[0]/packed/my-plugin-*.css";
+mkdir $_  for @READ_ONLY;
+chmod 0555, $_ for @READ_ONLY;
 
-$t = Test::Mojo->new;
+my $t = Test::Mojo->new;
 $t->app->mode('production');
 $t->app->routes->get('/test1' => 'test1');
 $t->app->static->paths([@READ_ONLY]);
 $t->app->plugin('AssetPack');
 
-$assetpack = $t->app->asset;
-is $assetpack->out_dir, '', 'in_memory assets';
+my $assetpack = $t->app->asset;
+plan skip_all => "Cannot run tests when @READ_ONLY is writeable" if 
$assetpack->out_dir;
 
 $t->app->plugin('t::SomePluginWithAssets');
 is $t->app->asset, $assetpack, 'same assetpack';
@@ -40,11 +36,11 @@
 );
 
 is $assetpack->_asset($names[0])->in_memory, 0, 'existing is bundled with 
t::SomePluginWithAssets';
-like $assetpack->_asset($names[0])->url, 
qr{t/read-only-with-existing-assets$href[0]$}, 'and stored in memory';
+like $assetpack->_asset($names[0])->path, 
qr{t/read-only-with-existing-assets$href[0]$}, 'and stored in memory';
 $t->get_ok($href[0])->status_is(200)->content_like(qr{color:\#aaa});
 
 is $assetpack->_asset($names[1])->in_memory, 1, 'new is regerated now and 
stored in memory';
-is $assetpack->_asset($names[1])->url, File::Spec->catfile('', $names[1]), 
'and has a virtual url';
+is $assetpack->_asset($names[1])->path, File::Spec->catfile('', $names[1]), 
'and has a virtual url';
 $t->get_ok($href[1])->status_is(200)->content_like(qr{color:\#bbb});
 
 chmod 0775, $_ for @READ_ONLY;
Files 
old/Mojolicious-Plugin-AssetPack-0.51/t/public/images/xyz/social-chrome.png and 
new/Mojolicious-Plugin-AssetPack-0.5201/t/public/images/xyz/social-chrome.png 
differ
Files 
old/Mojolicious-Plugin-AssetPack-0.51/t/public/images/xyz/social-github.png and 
new/Mojolicious-Plugin-AssetPack-0.5201/t/public/images/xyz/social-github.png 
differ
Files old/Mojolicious-Plugin-AssetPack-0.51/t/public/images/xyz/social-rss.png 
and new/Mojolicious-Plugin-AssetPack-0.5201/t/public/images/xyz/social-rss.png 
differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojolicious-Plugin-AssetPack-0.51/t/sprites.t 
new/Mojolicious-Plugin-AssetPack-0.5201/t/sprites.t
--- old/Mojolicious-Plugin-AssetPack-0.51/t/sprites.t   1970-01-01 
01:00:00.000000000 +0100
+++ new/Mojolicious-Plugin-AssetPack-0.5201/t/sprites.t 2015-04-20 
08:41:58.000000000 +0200
@@ -0,0 +1,21 @@
+use t::Helper;
+
+my $t = t::Helper->t({minify => 0});
+
+plan skip_all => $@ unless eval 'require Imager::File::PNG;1';
+
+$t->app->asset('my-sprites.css' => 'sprites:///images/xyz', '/test.css');
+
+$t->get_ok('/test1')
+  ->text_like('style', qr/\.xyz\.social-chrome \{ background-position: 0px 
-0px; width: 32px; height: 32px; \}/)
+  ->text_like('style', qr/\.xyz\.social-github \{ background-position: 0px 
-32px; width: 40px; height: 40px; \}/)
+  ->text_like('style', qr/\.xyz\.social-rss \{ background-position: 0px -72px; 
width: 34px; height: 30px; \}/)
+  ->text_like('style', qr/\.xyz \{ background: url\(xyz-\w+\.png\) no-repeat; 
display: inline-block; \}/);
+
+done_testing;
+
+__DATA__
+@@ test.css
+.xyz { display: block; }
+@@ test1.html.ep
+%= asset 'my-sprites.css', {inline => 1}


Reply via email to