Fix RandomAssetProxy macro.

This commit is contained in:
Colin Kuskie 2010-01-27 21:42:27 -08:00
parent 193d30ec41
commit b3faecae9b

View file

@ -13,6 +13,7 @@ package WebGUI::Macro::RandomAssetProxy;
use strict; use strict;
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::International; use WebGUI::International;
use WebGUI::Exception;
=head1 NAME =head1 NAME
@ -34,28 +35,29 @@ if no asset exists at that url, or if the asset has no children.
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub process { sub process {
my $session = shift; my $session = shift;
my $url = shift; my $url = shift;
my $i18n = WebGUI::International->new($session,'Macro_RandomAssetProxy'); my $i18n = WebGUI::International->new($session,'Macro_RandomAssetProxy');
my $asset = WebGUI::Asset->newByUrl($session, $url); my $asset = eval { WebGUI::Asset->newByUrl($session, $url); };
if (defined $asset) { if (Exception::Class->caught()) {
my $children = $asset->getLineage(["children"]); return $i18n->get('invalid url');
#randomize; }
my $randomAssetId = $children->[int(rand(scalar(@{$children})))];
my $randomAsset = WebGUI::Asset->newById($session,$randomAssetId); my $children = $asset->getLineage(["children"]);
if (defined $randomAsset) { #randomize;
if ($randomAsset->canView) { my $randomAssetId = $children->[int(rand(scalar(@{$children})))];
$randomAsset->toggleToolbar; my $randomAsset = eval { WebGUI::Asset->newById($session,$randomAssetId); };
$randomAsset->prepareView; if (Exception::Class->caught()) {
return $randomAsset->view; return $i18n->get('childless');
} }
return undef; elsif ($randomAsset->canView) {
} else { $randomAsset->toggleToolbar;
return $i18n->get('childless'); $randomAsset->prepareView;
} return $randomAsset->view;
} else { }
return $i18n->get('invalid url'); else {
} return undef;
}
} }