convert the resource classes to use the new Resource::Pack api
Jesse Luehrs [Thu, 15 Apr 2010 20:25:28 +0000 (15:25 -0500)]
lib/Moose/Website.pm
lib/Moose/Website/Resource/Templates.pm
lib/Moose/Website/Resource/WebFiles.pm
lib/Moose/Website/Resource/jQuery.pm

index 95e0f09..3c93f3f 100644 (file)
@@ -47,18 +47,19 @@ has 'template_resource' => (
     default => sub {
         Moose::Website::Resource::Templates->new
     },
-    handles  => {
-        'template_root' => 'dir'
-    }
 );
 
+sub template_root {
+    shift->template_resource->fetch('template_dir')->install_from_absolute;
+}
+
 has 'web_file_resource' => (
     traits  => [ 'NoGetopt' ],
     is      => 'ro',
     isa     => 'Moose::Website::Resource::WebFiles',
     lazy    => 1,
     default => sub {
-        Moose::Website::Resource::WebFiles->new
+        Moose::Website::Resource::WebFiles->new(install_to => shift->outdir)
     },
 );
 
@@ -128,7 +129,7 @@ sub run {
     }
 
     $self->log( "Copying web resources to " . $self->outdir );
-    $self->web_file_resource->copy( to => $self->outdir, include_deps => 1 );
+    $self->web_file_resource->install;
 }
 
 sub build_template_params {
index ba8dfa2..cab2a89 100644 (file)
@@ -1,18 +1,30 @@
 package Moose::Website::Resource::Templates;
 use Moose;
+use Resource::Pack;
 
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
-with 'Resource::Pack' => {
-    traits => [
-        'Resource::Pack::Dir'
-    ]
-};
+extends 'Resource::Pack::Resource';
+
+has '+name' => (default => 'templates');
+
+sub BUILD {
+    my $self = shift;
+
+    resource $self => as {
+        install_from(Path::Class::File->new(__FILE__)->parent
+                                                     ->subdir('Templates'));
+        dir template_dir => (
+            dir        => '.',
+            install_as => '',
+        );
+    };
+}
 
 __PACKAGE__->meta->make_immutable;
 
-no Moose; 1;
+no Moose; no Resource::Pack; 1;
 
 __END__
 
index f1fb51f..763bc0e 100644 (file)
@@ -1,21 +1,37 @@
 package Moose::Website::Resource::WebFiles;
 use Moose;
+use Resource::Pack;
+
+use Moose::Website::Resource::jQuery;
 
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
-with 'Resource::Pack' => {
-    traits => [
-        'Resource::Pack::Dir'
-    ],
-    depends_on => [
-        'Moose::Website::Resource::jQuery'
-    ]
-};
+extends 'Resource::Pack::Resource';
+
+has '+name' => (default => 'webfiles');
+
+sub BUILD {
+    my $self = shift;
+
+    resource $self => as {
+        install_from(Path::Class::File->new(__FILE__)->parent
+                                                     ->subdir('WebFiles'));
+
+        resource(Moose::Website::Resource::jQuery->new);
+
+        dir 'css';
+        dir 'images';
+        dir js => (
+            dir          => 'js',
+            dependencies => ['jquery/core'],
+        );
+    };
+}
 
 __PACKAGE__->meta->make_immutable;
 
-no Moose; 1;
+no Moose; no Resource::Pack; 1;
 
 __END__
 
index 330e9ff..2d3ca74 100644 (file)
@@ -1,21 +1,26 @@
 package Moose::Website::Resource::jQuery;
 use Moose;
+use Resource::Pack;
 
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
-with 'Resource::Pack' => {
-    traits => [
-        'Resource::Pack::URL' => {
-            url     => 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js',
-            sub_dir => 'js'
-        }
-    ]
-};
+extends 'Resource::Pack::Resource';
+
+has '+name' => (default => 'jquery');
+
+sub BUILD {
+    my $self = shift;
+
+    resource $self => as {
+        install_to 'js';
+        url core => 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
+    };
+}
 
 __PACKAGE__->meta->make_immutable;
 
-no Moose; 1;
+no Moose; no Resource::Pack; 1;
 
 __END__