From 8266dfd69acd08520cba6dd91f49ed97cb60d689 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 28 May 2004 16:00:28 +0000 Subject: [PATCH] plug-ins are now dynamically loaded --- docs/changelog/6.x.x.txt | 4 ++++ docs/gotcha.txt | 5 +++++ docs/migration.txt | 8 ++++++++ lib/WebGUI.pm | 3 +++ lib/WebGUI/Macro.pm | 6 +++++- lib/WebGUI/Macro/AdminBar.pm | 3 +++ lib/WebGUI/Operation/Auth.pm | 5 ++++- lib/WebGUI/Operation/Package.pm | 3 +++ lib/WebGUI/Operation/Trash.pm | 9 +++++++++ lib/WebGUI/Page.pm | 3 +++ lib/WebGUI/Session.pm | 34 --------------------------------- 11 files changed, 47 insertions(+), 36 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index aee3bc0c2..6506eb0ae 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -3,6 +3,10 @@ - Added a --history option to upgrade.pl that displays the upgrade history for each site. - Fixed a typo in User.pm + - All plugins are now dynamically loaded. This provides a performance gain of + over 100% in CGI mode, 10% in mod_perl mode, and less memory usage in + mod_perl mode. + 6.0.3 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 9c81c47b7..d2958210e 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -8,6 +8,11 @@ versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +6.1.0 +-------------------------------------------------------------------- + * See docs/migration.txt for changes in plug-in coding. + + 6.0.2 -------------------------------------------------------------------- * You need to add all of your site aliases to the sitename variable diff --git a/docs/migration.txt b/docs/migration.txt index b9864a0d4..a9954af7d 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -103,5 +103,13 @@ way, including the constructor. We removed depricated parameters from the method which will cause pagination not to function in items that have not been updated. +5.4 Dynamic Plug-in Loading + +In 6.1 plug-ins (Wobjects, Macros, and Auth) are all dynamically loaded. They +used to be statically loaded at session open time. If you are writing +something that uses a macro, wobject, or auth module outside of the usual +mechanisms that call those plug-ins, then you'll need to write a piece of code +to load the plug-in at use time. + diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 773d91099..91a0dc271 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -94,6 +94,9 @@ sub _processFunctions { } else { if (WebGUI::Privilege::canViewPage()) { $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + my $load = "use ".$cmd; # gotta load the wobject before you can use it + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); $w = eval{$cmd->new($wobject)}; WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root Cause: ".$@) if($@); if ($session{form}{func} =~ /^[A-Za-z]+$/) { diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index 9c04801ee..133013266 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -167,7 +167,11 @@ sub process { $params = &process($params); # recursive process params } if ($session{config}{macros}{$searchString} ne "") { - my $cmd = "WebGUI::Macro::".$session{config}{macros}{$searchString}."::process"; + my $cmd = "WebGUI::Macro::".$session{config}{macros}{$searchString}; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Macro failed to compile: $cmd.".$@) if($@); + $cmd = $cmd."::process"; my $result = eval{&$cmd($params)}; if ($@) { WebGUI::ErrorHandler::warn("Processing failed on macro: $macro: ".$@); diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index 7839587b2..be8ff08e3 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -52,6 +52,9 @@ sub process { $var{'contentTypes.label'} = WebGUI::International::get(1083); foreach my $namespace (@{$session{config}{wobjects}}) { my $cmd = "WebGUI::Wobject::".$namespace; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); my $w = eval{$cmd->new({namespace=>$namespace,wobjectId=>"new"})}; if ($@) { WebGUI::ErrorHandler::warn("Could not use wobject $namespace because: ".$@); diff --git a/lib/WebGUI/Operation/Auth.pm b/lib/WebGUI/Operation/Auth.pm index dfe8c94b5..052b779e5 100644 --- a/lib/WebGUI/Operation/Auth.pm +++ b/lib/WebGUI/Operation/Auth.pm @@ -41,6 +41,9 @@ sub getInstance { my $userId = $_[1]; #Create Auth Object my $cmd = "WebGUI::Auth::".$authMethod; + my $load = "use ".$cmd; + WebGUI::ErrorHandler::fatalError("Authentication module failed to compile: $cmd.".$@) if($@); + eval($load); my $auth = eval{$cmd->new($authMethod,$userId)}; WebGUI::ErrorHandler::fatalError("Couldn't instanciate authentication module: $authMethod. Root cause: ".$@) if($@); return $auth; @@ -100,4 +103,4 @@ sub www_recoverPassword { return www_auth("recoverPassword"); } -1; \ No newline at end of file +1; diff --git a/lib/WebGUI/Operation/Package.pm b/lib/WebGUI/Operation/Package.pm index 8b158edef..aea14a994 100644 --- a/lib/WebGUI/Operation/Package.pm +++ b/lib/WebGUI/Operation/Package.pm @@ -29,6 +29,9 @@ sub _duplicateWobjects { my $sth = WebGUI::SQL->read("select * from wobject where pageId=$_[0] order by sequenceNumber"); while (my $wobject = $sth->hashRef) { my $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); my $w = $cmd->new($wobject); $w->duplicate($_[1]); } diff --git a/lib/WebGUI/Operation/Trash.pm b/lib/WebGUI/Operation/Trash.pm index 554fe9308..cf8952666 100644 --- a/lib/WebGUI/Operation/Trash.pm +++ b/lib/WebGUI/Operation/Trash.pm @@ -42,6 +42,9 @@ sub _purgeUserTrash { where wobjectId=".$base->{wobjectId}); %properties = (%{$base}, %{$extended}); $cmd = "WebGUI::Wobject::".$properties{namespace}; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); $w = $cmd->new(\%properties); $w->purge; } @@ -70,6 +73,9 @@ sub _purgeWobject { where wobjectId=".$base->{wobjectId}); %properties = (%{$base}, %{$extended}); $cmd = "WebGUI::Wobject::".$properties{namespace}; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); $w = $cmd->new(\%properties); $w->purge; } @@ -86,6 +92,9 @@ sub _purgeWobjects { where wobjectId=".$base->{wobjectId}); %properties = (%{$base}, %{$extended}); $cmd = "WebGUI::Wobject::".$properties{namespace}; + my $load = "use ".$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); $w = $cmd->new(\%properties); $w->purge; } diff --git a/lib/WebGUI/Page.pm b/lib/WebGUI/Page.pm index 4d11e0696..4c1a1bcbb 100644 --- a/lib/WebGUI/Page.pm +++ b/lib/WebGUI/Page.pm @@ -363,6 +363,9 @@ sub generate { } } my $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + my $load = 'use '.$cmd; + eval($load); + WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); my $w = eval{$cmd->new($wobject)}; WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@); push(@{$var{'position'.$wobject->{templatePosition}.'_loop'}},{ diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 99df0f87e..e46a61c06 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -169,37 +169,6 @@ sub _time { } -#------------------------------------------------------------------- -sub _loadAuthentication { - foreach my $namespace (@{$session{config}{authMethods}}) { - my $cmd = "use WebGUI::Auth::".$namespace; - eval($cmd); - if ($@) { - WebGUI::ErrorHandler::warn("Authentication module failed to compile: $namespace. ".$@); - } - } -} - -#------------------------------------------------------------------- -sub _loadMacros { - foreach my $key (keys %{$session{config}{macros}}) { - my $cmd = "use WebGUI::Macro::".$session{config}{macros}{$key}; - eval($cmd); - WebGUI::ErrorHandler::fatalError("Macro failed to compile: $key.".$@) if($@); - } -} - -#------------------------------------------------------------------- -sub _loadWobjects { - foreach my $namespace (@{$session{config}{wobjects}}) { - my $cmd = "use WebGUI::Wobject::".$namespace; - eval($cmd); - if ($@) { - WebGUI::ErrorHandler::warn("Wobject failed to compile: $namespace. ".$@); - } - } -} - #------------------------------------------------------------------- # This routine returns an unique session Id. sub _uniqueSessionId { @@ -467,9 +436,6 @@ sub open { $session{language} = WebGUI::SQL->quickHashRef("select * from language where languageId=$session{user}{language}"); ###---------------------------- ### loading plugins - _loadWobjects(); - _loadMacros(); - _loadAuthentication(); } #-------------------------------------------------------------------