From 10e5e90668b42d5cccba8de954b11c7e7f757b77 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Thu, 26 Jul 2007 20:40:38 +0000 Subject: [PATCH] fix: workflow helpers and form helpers now use UNIVERSAL->can instead of evil evals --- lib/WebGUI/Operation/FormHelpers.pm | 27 +++++++++++++++++---------- lib/WebGUI/Operation/Workflow.pm | 27 +++++++++++++++++---------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/lib/WebGUI/Operation/FormHelpers.pm b/lib/WebGUI/Operation/FormHelpers.pm index df44ff0bb..b2e43a8d5 100644 --- a/lib/WebGUI/Operation/FormHelpers.pm +++ b/lib/WebGUI/Operation/FormHelpers.pm @@ -42,24 +42,31 @@ parameters you wish the form helper to use. Here's an example: =cut sub www_formHelper { - my $session = shift; - my $form = $session->form; - my $class = "WebGUI::Form::".$form->get("class"); - my $sub = $form->get("sub"); + my $session = shift; + my $form = $session->form; + my $class = "WebGUI::Form::".$form->get("class"); + my $sub = $form->get("sub"); return "ERROR" unless (defined $sub && defined $class); + + # Load the form helper class my $load = "use ".$class; eval($load); if ($@) { $session->errorHandler->error("Couldn't load form helper class $class because $@"); return "ERROR"; } - my $output = ""; - my $command = $class.'::www_'.$sub; - no strict; - my $output = eval { &$command($session) }; - use strict; + + # Make sure the subroutine exists + my $command = $class->can('www_'.$sub); + if (!$command) { + $session->errorHandler->error("Could not execute form helper: Couldn't find subroutine www_$sub via class $class"); + return "ERROR"; + } + + # Run the subroutine + my $output = eval { $command->($session) }; if ($@) { - $session->errorHandler->error("Couldn't execute form helper subroutine $sub because $@"); + $session->errorHandler->error("Couldn't execute form helper ${class}::www_${sub} because $@"); return "ERROR"; } return $output; diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index 8007c84b2..ec98e09a6 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -74,24 +74,31 @@ parameters you wish the activity helper to use. Here's an example: =cut sub www_activityHelper { - my $session = shift; - my $form = $session->form; - my $class = "WebGUI::Workflow::Activity::".$form->get("class"); - my $sub = $form->get("sub"); + my $session = shift; + my $form = $session->form; + my $class = "WebGUI::Workflow::Activity::".$form->get("class"); + my $sub = $form->get("sub"); return "ERROR" unless (defined $sub && defined $class); + + # Load the modules my $load = "use ".$class; eval($load); if ($@) { $session->errorHandler->error("Couldn't load activity helper class $class because $@"); return "ERROR"; } - my $output = ""; - my $command = $class.'::www_'.$sub; - no strict; - my $output = eval { &$command($session) }; - use strict; + + # Make sure the subroutine exists + my $command = $class->can('www_'.$sub); + if (!$command) { + $session->errorHandler->error("Couldn't execute activity helper ${class}::www_${sub} because subroutine does not exist"); + return "ERROR"; + } + + # Execute + my $output = eval { $command->($session) }; if ($@) { - $session->errorHandler->error("Couldn't execute activity helper subroutine $sub because $@"); + $session->errorHandler->error("Couldn't execute activity helper ${class}::www_${sub} because $@"); return "ERROR"; } return $output;