switched macro system to use WebGUI::Pluggable

This commit is contained in:
JT Smith 2008-01-04 01:06:54 +00:00
parent 058a6353a1
commit 1066bb4dba

View file

@ -15,8 +15,8 @@ package WebGUI::Macro;
=cut =cut
use strict qw(vars subs); use strict;
use WebGUI::Pluggable;
=head1 NAME =head1 NAME
@ -118,38 +118,34 @@ A scalar reference of HTML to be processed.
=cut =cut
sub process { sub process {
my $session = shift; my $session = shift;
my $content = shift; my $content = shift;
while ($$content =~ /$nestedMacro/gs) { while ($$content =~ /$nestedMacro/gs) {
my ($macro, $searchString, $params) = ($1, $2, $3); my ($macro, $searchString, $params) = ($1, $2, $3);
next if ($searchString =~ /^\d+$/); # don't process ^0; ^1; ^2; etc. next if ($searchString =~ /^\d+$/); # don't process ^0; ^1; ^2; etc.
next if ($searchString =~ /^\-$/); # don't process ^-; next if ($searchString =~ /^\-$/); # don't process ^-;
if ($params ne "") { if ($params ne "") {
$params =~ s/(^\(|\)$)//g; # remove parenthesis $params =~ s/(^\(|\)$)//g; # remove parenthesis
&process($session,\$params); # recursive process params &process($session,\$params); # recursive process params
} }
my $macros = $session->config->get("macros"); my $macros = $session->config->get("macros");
if ($macros->{$searchString} ne "") { if ($macros->{$searchString} ne "") {
my $cmd = "WebGUI::Macro::".$macros->{$searchString}; my @param;
my $load = "use ".$cmd; push(@param, $+) while $params =~ m {
eval($load); "([^\"\\]*(?:\\.[^\"\\]*)*)",?
$session->errorHandler->error("Macro failed to compile: $cmd.".$@) if($@); | ([^,]+),?
my @param; | ,
push(@param, $+) while $params =~ m { }gx;
"([^\"\\]*(?:\\.[^\"\\]*)*)",? push(@param, undef) if substr($params,-1,1) eq ',';
| ([^,]+),? my $result = eval { WebGUI::Pluggable::run("WebGUI::Macro::".$macros->{$searchString}, "process", [ $session, @param ] ) };
| , if ( $@ ) {
}gx; $session->errorHandler->error($@);
push(@param, undef) if substr($params,-1,1) eq ','; }
$cmd = $cmd."::process"; else {
my $result = eval{&$cmd($session,@param)};
if ($@) {
$session->errorHandler->error("Processing failed on macro: $macro: ".$@);
} else {
if ($result =~ /\Q$macro/) { if ($result =~ /\Q$macro/) {
$result = "Endless macro loop detected. Stopping recursion."; $result = "Endless macro loop detected. Stopping recursion.";
$session->errorHandler->warn($macro." : ".$result) $session->errorHandler->error($macro." : ".$result);
} }
$$content =~ s/\Q$macro/$result/ges; $$content =~ s/\Q$macro/$result/ges;
} }
} }