diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 2b05168a5..398ae446f 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -22,6 +22,7 @@ use WebGUI::Asset; use WebGUI::Asset::RichEdit; use WebGUI::Asset::Template; use WebGUI::International; +use WebGUI::Pluggable; use WebGUI::Utility; =head1 NAME @@ -64,14 +65,12 @@ sub AUTOLOAD { my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); my $session = shift; my @params = @_; - my $cmd = "use WebGUI::Form::".$name; - eval ($cmd); - if ($@) { - $session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@); - return; - } - my $class = "WebGUI::Form::".$name; - return $class->new($session,@params)->toHtml; + my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $session, @params ]) }; + if ($@) { + $session->errorHandler->error($@); + return; + } + return $control->toHtml; } diff --git a/lib/WebGUI/FormValidator.pm b/lib/WebGUI/FormValidator.pm index 920f2d1f2..e916e6a02 100644 --- a/lib/WebGUI/FormValidator.pm +++ b/lib/WebGUI/FormValidator.pm @@ -16,6 +16,7 @@ package WebGUI::FormValidator; use strict qw(vars subs); use WebGUI::HTML; +use WebGUI::Pluggable; =head1 NAME @@ -70,14 +71,12 @@ sub AUTOLOAD { my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); $params = {name=>$params} if ref ($params) ne "HASH"; - my $cmd = "use WebGUI::Form::".$name; - eval ($cmd); - if ($@) { - $self->session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@); - return; - } - my $class = "WebGUI::Form::".$name; - return $class->new($self->session, $params)->getValueFromPost(@args); + my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, $params ]) }; + if ($@) { + $self->session->errorHandler->error($@); + return; + } + return $control->getValueFromPost(@args); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 11d41c9e9..bb3e9504d 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -18,6 +18,7 @@ use CGI::Util qw(rearrange); use strict qw(vars refs); use WebGUI::Form; use WebGUI::International; +use WebGUI::Pluggable; use WebGUI::Utility; =head1 NAME @@ -63,7 +64,8 @@ sub _uiLevelChecksOut { my $self = shift; if ($_[0] <= $self->session->user->profileField("uiLevel")) { return 1; - } else { + } + else { return 0; } } @@ -77,20 +79,18 @@ Dynamically creates functions on the fly for all the different form control type =cut sub AUTOLOAD { - our $AUTOLOAD; + our $AUTOLOAD; my $self = shift; - my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); - my %params = @_; + my $name = ucfirst((split /::/, $AUTOLOAD)[-1]); + my %params = @_; $params{uiLevelOverride} ||= $self->{_uiLevelOverride}; $params{rowClass} ||= $self->{_class}; - my $cmd = "use WebGUI::Form::".$name; - eval ($cmd); - if ($@) { - $self->session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@); - return; - } - my $class = "WebGUI::Form::".$name; - $self->{_data} .= $class->new($self->session,%params)->toHtmlWithWrapper; + my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, %params ]) }; + if ($@) { + $self->session->errorHandler->error($@); + return; + } + $self->{_data} .= $control->toHtmlWithWrapper; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Operation/FormHelpers.pm b/lib/WebGUI/Operation/FormHelpers.pm index b2e43a8d5..12a2920c6 100644 --- a/lib/WebGUI/Operation/FormHelpers.pm +++ b/lib/WebGUI/Operation/FormHelpers.pm @@ -16,6 +16,7 @@ use WebGUI::Asset; use WebGUI::Asset::Wobject::Folder; use WebGUI::Form::Group; use WebGUI::HTMLForm; +use WebGUI::Pluggable; use WebGUI::Storage::Image; use WebGUI::Utility; @@ -47,26 +48,9 @@ sub www_formHelper { 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); + my $output = eval { WebGUI::Pluggable::instanciate($class, "www_".$sub, [$session]) }; if ($@) { - $session->errorHandler->error("Couldn't load form helper class $class because $@"); - return "ERROR"; - } - - # 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 ${class}::www_${sub} because $@"); + $session->errorHandler->error($@); return "ERROR"; } return $output;