diff --git a/lib/WebGUI/FilePump/Admin.pm b/lib/WebGUI/FilePump/Admin.pm
index 84bfa9be9..2755c9a0a 100644
--- a/lib/WebGUI/FilePump/Admin.pm
+++ b/lib/WebGUI/FilePump/Admin.pm
@@ -86,7 +86,7 @@ sub www_addBundleSave {
return $session->privilege->insufficient() unless canView($session);
my $form = $session->form;
my $bundleName = $form->get('bundleName');
- my $bundle = WebGUI::FilePump::Bundle->create($session, {
+ my $bundle = WebGUI::FilePump::Bundle->new($session, {
bundleName => $bundleName,
lastModified => time(),
});
@@ -273,7 +273,7 @@ EOTABLE
;
my $rows = '';
- my $files = $bundle->get($fileType);
+ my $files = $bundle->$fileType;
foreach my $file (@{ $files }) {
my $urlFrag = 'bundleId='.$bundleId.';fileType='.$type.';fileId='.$file->{fileId};
$rows .= sprintf '
| %s | %s | %s |
',
@@ -342,20 +342,20 @@ sub www_manage {
my $getABundle = WebGUI::FilePump::Bundle->getAllIterator($session,{ orderBy => 'bundleName' } );
my $notYet = $i18n->get('not yet');
while (my $bundle = $getABundle->()) {
- my $lastModified = $bundle->get('lastModified');
- my $lastBuild = $bundle->get('lastBuild');
+ my $lastModified = $bundle->lastModified;
+ my $lastBuild = $bundle->lastBuild;
my $build = '';
if ($lastModified > $lastBuild) {
$build = sprintf q| (%s)|,
- $url->gateway($url->getRequestedUrl,'op=filePump;func=buildBundle;bundleId='.$bundle->getId),
+ $url->gateway($url->getRequestedUrl,'op=filePump;func=buildBundle;bundleId='.$bundle->bundleId),
$i18n->get('build');
}
$rows .= sprintf '| %s | %s | %s | %s | ',
- $session->icon->delete('op=filePump;func=deleteBundle;bundleId='.$bundle->getId),
- $url->gateway($url->getRequestedUrl,'op=filePump;func=editBundle;bundleId='.$bundle->getId),
- $bundle->get('bundleName'),
- $bundle->get('lastModified') ? $dt->epochToHuman($lastModified) : $notYet,
- $bundle->get('lastBuild') ? $dt->epochToHuman($lastBuild).$build : $notYet,
+ $session->icon->delete('op=filePump;func=deleteBundle;bundleId='.$bundle->bundleId),
+ $url->gateway($url->getRequestedUrl,'op=filePump;func=editBundle;bundleId='.$bundle->bundleId),
+ $bundle->bundleName,
+ $bundle->lastModified ? $dt->epochToHuman($lastModified) : $notYet,
+ $bundle->lastBuild ? $dt->epochToHuman($lastBuild).$build : $notYet,
;
}
my $output = sprintf <get('bundle name'), $i18n->get('last modified'), $i18n->get('last build'), $rows;
diff --git a/lib/WebGUI/FilePump/Bundle.pm b/lib/WebGUI/FilePump/Bundle.pm
index 54f27558d..c43a6436e 100644
--- a/lib/WebGUI/FilePump/Bundle.pm
+++ b/lib/WebGUI/FilePump/Bundle.pm
@@ -1,6 +1,61 @@
package WebGUI::FilePump::Bundle;
-use base qw/WebGUI::Crud WebGUI::JSONCollateral/;
+use Moose;
+use WebGUI::Definition::Crud;
+extends 'WebGUI::Crud';
+define tableName => 'filePumpBundle';
+define tableKey => 'bundleId';
+has bundleId => (
+ required => 1,
+ is => 'ro',
+);
+property bundleName => (
+ label => 'bundleName',
+ fieldType => 'text',
+ builder => '_default_bundleName',
+ lazy => 1,
+);
+sub _default_bundleName {
+ my $session = shift->session;
+ my $i18n = WebGUI::International->new($session, 'FilePump');
+ return $i18n->get('new bundle');
+}
+property lastModified => (
+ label => 'lastModified',
+ fieldType => 'integer',
+ default => 0,
+);
+property lastBuild => (
+ label => 'lastBuild',
+ fieldType => 'integer',
+ default => 0,
+);
+property jsFiles => (
+ label => 'jsFiles',
+ fieldType => 'textarea',
+ default => sub { [] },
+ traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
+ isa => 'WebGUI::Type::JSONArray',
+ coerce => 1,
+);
+property cssFiles => (
+ label => 'cssFiles',
+ fieldType => 'textarea',
+ default => sub { [] },
+ traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
+ isa => 'WebGUI::Type::JSONArray',
+ coerce => 1,
+);
+property otherFiles => (
+ label => 'otherFiles',
+ fieldType => 'textarea',
+ default => sub { [] },
+ traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
+ isa => 'WebGUI::Type::JSONArray',
+ coerce => 1,
+);
+with 'WebGUI::Role::Asset::JSONCollateral';
+
use strict;
use WebGUI::Asset;
use WebGUI::International;
@@ -17,6 +72,44 @@ use Data::Dumper;
#-------------------------------------------------------------------
+=head2 properties
+
+=head3 tableName
+
+filePumpBundle
+
+=head3 tableKey
+
+bundleId
+
+=head3 sequenceKey
+
+None. Bundles have no sequence amongst themselves.
+
+=head3 properties
+
+=head4 bundleName
+
+The name of a bundle
+
+=head4 lastBuild
+
+The date the bundle was last built. This is used to generate the name of the bundled files
+for this bundle.
+
+=head4 lastModified
+
+The date the bundle was last modified. With this, and the lastBuild date, you can determine
+which bundles need to be rebuilt.
+
+=head4 jsFiles, cssFiles, otherFiles
+
+JSON blobs with files attached to the bundle. js = javascript, css = Cascading Style Sheets, other
+means anything else.
+
+=cut
+#-------------------------------------------------------------------
+
=head2 addFile ( $type, $uri )
Adds a file of the requested type to the bundle. Returns 1 if the add was successful.
@@ -42,7 +135,7 @@ sub addFile {
my $collateralType = $type eq 'JS' ? 'jsFiles'
: $type eq 'CSS' ? 'cssFiles'
: 'otherFiles';
- my $files = $self->get($collateralType);
+ my $files = $self->$collateralType;
my $uriExists = $self->getJSONCollateralDataIndex($files, 'uri', $uri) != -1 ? 1 : 0;
return 0, 'Duplicate URI' if $uriExists;
@@ -91,13 +184,13 @@ the method returns 0, along with an error message.
sub build {
my ($self) = @_;
my $newBuild = time();
- my $originalBuild = $self->get('lastBuild');
+ my $originalBuild = $self->lastBuild;
##Whole lot of building
my $error = undef;
##JavaScript first
- my $jsFiles = $self->get('jsFiles');
+ my $jsFiles = $self->jsFiles;
my $concatenatedJS = '';
JSFILE: foreach my $jsFile (@{ $jsFiles }) {
my $uri = $jsFile->{uri};
@@ -112,7 +205,7 @@ sub build {
return (0, $error) if ($error);
##CSS next
- my $cssFiles = $self->get('cssFiles');
+ my $cssFiles = $self->cssFiles;
my $concatenatedCSS = '';
CSSFILE: foreach my $cssFile (@{ $cssFiles }) {
my $uri = $cssFile->{uri};
@@ -138,7 +231,7 @@ sub build {
}
##Copy files over
- my $otherFiles = $self->get('otherFiles');
+ my $otherFiles = $self->otherFiles;
OTHERFILE: foreach my $file (@{ $otherFiles }) {
my $uri = $file->{uri};
my $results = $self->fetch($uri);
@@ -287,84 +380,6 @@ sub _buildFile {
return 0;
}
-#-------------------------------------------------------------------
-
-=head2 crud_definition
-
-WebGUI::Crud definition for this class.
-
-=head3 tableName
-
-filePumpBundle
-
-=head3 tableKey
-
-bundleId
-
-=head3 sequenceKey
-
-None. Bundles have no sequence amongst themselves.
-
-=head3 properties
-
-=head4 bundleName
-
-The name of a bundle
-
-=head4 lastBuild
-
-The date the bundle was last built. This is used to generate the name of the bundled files
-for this bundle.
-
-=head4 lastModified
-
-The date the bundle was last modified. With this, and the lastBuild date, you can determine
-which bundles need to be rebuilt.
-
-=head4 jsFiles, cssFiles, otherFiles
-
-JSON blobs with files attached to the bundle. js = javascript, css = Cascading Style Sheets, other
-means anything else.
-
-=cut
-
-sub crud_definition {
- my ($class, $session) = @_;
- my $definition = $class->SUPER::crud_definition($session);
- my $i18n = WebGUI::International->new($session, 'FilePump');
- $definition->{tableName} = 'filePumpBundle';
- $definition->{tableKey} = 'bundleId';
- $definition->{sequenceKey} = '';
- my $properties = $definition->{properties};
- $properties->{bundleName} = {
- fieldType => 'text',
- defaultValue => $i18n->get('new bundle'),
- };
- $properties->{lastModified} = {
- fieldType => 'integer',
- defaultValue => 0,
- };
- $properties->{lastBuild} = {
- fieldType => 'integer',
- defaultValue => 0,
- };
- $properties->{jsFiles} = {
- fieldType => 'textarea',
- defaultValue => [],
- serialize => 1,
- };
- $properties->{cssFiles} = {
- fieldType => 'textarea',
- defaultValue => [],
- serialize => 1,
- };
- $properties->{otherFiles} = {
- fieldType => 'textarea',
- defaultValue => [],
- serialize => 1,
- };
- return $definition;
-}
#-------------------------------------------------------------------
@@ -514,7 +529,7 @@ sub fetchAsset {
return {} if Exception::Class->caught();
##Check for a snippet, or snippet subclass?
my $guts = {
- lastModified => $asset->get('lastModified'),
+ lastModified => $asset->lastModified,
content => '',
};
if ($asset->isa('WebGUI::Asset::Snippet')) {
@@ -522,7 +537,7 @@ sub fetchAsset {
WebGUI::Macro::process($self->session, \( $guts->{content} ) );
}
elsif ($asset->isa('WebGUI::Asset::File')) {
- $guts->{content} = $asset->getStorageLocation->getFileContentsAsScalar($asset->get('filename'));
+ $guts->{content} = $asset->getStorageLocation->getFileContentsAsScalar($asset->filename);
}
return $guts;
}
@@ -640,7 +655,7 @@ Returns a urlized version of the bundle name, safe for URLs and filenames.
sub bundleUrl {
my ($self) = @_;
- return $self->session->url->urlize($self->get('bundleName'));
+ return $self->session->url->urlize($self->bundleName);
}
#-------------------------------------------------------------------
@@ -658,7 +673,7 @@ Another time stamp to use instead of the lastModified timestamp.
sub getPathClassDir {
my ($self, $lastBuild) = @_;
- $lastBuild ||= $self->get('lastBuild');
+ $lastBuild ||= $self->lastBuild;
return Path::Class::Dir->new(
$self->session->config->get('uploadsPath'),
'filepump',
diff --git a/t/FilePump/Bundle.t b/t/FilePump/Bundle.t
index 28e32145d..8e5469571 100644
--- a/t/FilePump/Bundle.t
+++ b/t/FilePump/Bundle.t
@@ -32,16 +32,17 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
-plan tests => 64;
+plan tests => 65;
#----------------------------------------------------------------------------
# put your tests here
use WebGUI::FilePump::Bundle;
-my $bundle = WebGUI::FilePump::Bundle->create($session);
+my $bundle = WebGUI::FilePump::Bundle->new($session);
isa_ok($bundle, 'WebGUI::FilePump::Bundle');
isa_ok($bundle, 'WebGUI::Crud');
+can_ok($bundle, qw/update write getJSONCollateralDataIndex/);
is($bundle->get('lastModified'), 0, 'by default, lastModified is 0');
@@ -449,7 +450,7 @@ ok(!-e $buildDir->stringify, 'delete deletes the current build directory');
my @jsFiles = qw/hoverhelp.js inputcheck.js/;
foreach my $jsFile (@jsFiles) {
- my $bundle = WebGUI::FilePump::Bundle->create($session);
+ my $bundle = WebGUI::FilePump::Bundle->new($session);
$bundle->addFile('JS', 'file:extras/'.$jsFile);
lives_ok { $bundle->build } "built file $jsFile";
$bundle->delete;