Module invoker can now accept arbitrary argument hashes to pass to modules.
This commit is contained in:
parent
1303431bdd
commit
001992af81
47
Modules.pm
47
Modules.pm
@ -36,7 +36,7 @@ BEGIN {
|
|||||||
$VERSION = 0.1;
|
$VERSION = 0.1;
|
||||||
$errstr = '';
|
$errstr = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Creation
|
# Creation
|
||||||
|
|
||||||
@ -45,7 +45,6 @@ BEGIN {
|
|||||||
# to create block modules on the fly.
|
# to create block modules on the fly.
|
||||||
# cgi - The CGI object to access parameters and cookies through.
|
# cgi - The CGI object to access parameters and cookies through.
|
||||||
# dbh - The database handle to use for queries.
|
# dbh - The database handle to use for queries.
|
||||||
# phpbb - An object through which to talk to a phpBB3 database
|
|
||||||
# settings - The system settings object
|
# settings - The system settings object
|
||||||
# template - The system template object
|
# template - The system template object
|
||||||
# session - The session object
|
# session - The session object
|
||||||
@ -76,7 +75,7 @@ sub new {
|
|||||||
return set_error("No settings object available.") if(!$self -> {"settings"});
|
return set_error("No settings object available.") if(!$self -> {"settings"});
|
||||||
|
|
||||||
# ... finally, template
|
# ... finally, template
|
||||||
return set_error("No settings template available.") if(!$self -> {"template"});
|
return set_error("No template object available.") if(!$self -> {"template"});
|
||||||
|
|
||||||
# update @INC if needed
|
# update @INC if needed
|
||||||
unshift(@INC, $self -> {"blockdir"}) if($self -> {"blockdir"});
|
unshift(@INC, $self -> {"blockdir"}) if($self -> {"blockdir"});
|
||||||
@ -114,17 +113,17 @@ sub new_module_byblockid {
|
|||||||
my $modrow = $sth -> fetchrow_hashref();
|
my $modrow = $sth -> fetchrow_hashref();
|
||||||
|
|
||||||
# If we have a block row, return an instance of the module for it
|
# If we have a block row, return an instance of the module for it
|
||||||
return $self -> new_module_byid($modrow -> {"module_id"},
|
return $self -> new_module_byid($modrow -> {"module_id"},
|
||||||
$modrow -> {"args"})
|
$modrow -> {"args"})
|
||||||
if($modrow);
|
if($modrow);
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## @method $ new_module_byname($modname, $argument)
|
## @method $ new_module_byname($modname, $argument)
|
||||||
# Load a module based on its name, checking against the database to obtain the real
|
# Load a module based on its name, checking against the database to obtain the real
|
||||||
# module name, and whether the module is active. Returns a new object of the module
|
# module name, and whether the module is active. Returns a new object of the module
|
||||||
# on success, undef if the module is disabled or if there's a problem.
|
# on success, undef if the module is disabled or if there's a problem.
|
||||||
#
|
#
|
||||||
# @param modname The name of the module to load.
|
# @param modname The name of the module to load.
|
||||||
@ -139,11 +138,11 @@ sub new_module_byname {
|
|||||||
$modname,
|
$modname,
|
||||||
$argument);
|
$argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## @method $ new_module_byid($modid, $argument)
|
|
||||||
|
## @method $ new_module_byid($modid, $argument)
|
||||||
# Load a module based on its id, checking against the database to obtain the real
|
# Load a module based on its id, checking against the database to obtain the real
|
||||||
# module name, and whether the module is active. Returns a new object of the module
|
# module name, and whether the module is active. Returns a new object of the module
|
||||||
# on success, undef if the module is disabled or if there's a problem.
|
# on success, undef if the module is disabled or if there's a problem.
|
||||||
#
|
#
|
||||||
# @param modid The id of the module to load.
|
# @param modid The id of the module to load.
|
||||||
@ -155,7 +154,7 @@ sub new_module_byid {
|
|||||||
my $argument = shift;
|
my $argument = shift;
|
||||||
|
|
||||||
return $self -> _new_module_internal("WHERE module_id = ?",
|
return $self -> _new_module_internal("WHERE module_id = ?",
|
||||||
$modid,
|
$modid,
|
||||||
$argument);
|
$argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,9 +174,9 @@ sub _new_module_internal {
|
|||||||
my $modarg = shift;
|
my $modarg = shift;
|
||||||
|
|
||||||
my $modh = $self -> {"dbh"} -> prepare("SELECT * FROM ".$self -> {"settings"} -> {"database"} -> {"modules"}." $where");
|
my $modh = $self -> {"dbh"} -> prepare("SELECT * FROM ".$self -> {"settings"} -> {"database"} -> {"modules"}." $where");
|
||||||
$modh -> execute($argument)
|
$modh -> execute($argument)
|
||||||
or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute module resolve query: ".$self -> {"dbh"} -> errstr);
|
or die_log($self -> {"cgi"} -> remote_host(), "Unable to execute module resolve query: ".$self -> {"dbh"} -> errstr);
|
||||||
|
|
||||||
my $modrow = $modh -> fetchrow_hashref();
|
my $modrow = $modh -> fetchrow_hashref();
|
||||||
|
|
||||||
# bomb if the mofule record is not found, or the module is inactive
|
# bomb if the mofule record is not found, or the module is inactive
|
||||||
@ -186,15 +185,17 @@ sub _new_module_internal {
|
|||||||
my $name = $modrow -> {"perl_module"};
|
my $name = $modrow -> {"perl_module"};
|
||||||
no strict "refs"; # must disable strict references to allow named module loading.
|
no strict "refs"; # must disable strict references to allow named module loading.
|
||||||
require "$name.pm";
|
require "$name.pm";
|
||||||
my $modobj = $name -> new($modrow -> {"id"},
|
|
||||||
$modarg,
|
# Set up the module argument hash...
|
||||||
$self -> {"cgi"},
|
my %args = { "modid" => $modrow -> {"id"},
|
||||||
$self -> {"dbh"},
|
"args" => $modarg,
|
||||||
$self -> {"phpbb"},
|
"module" => $self,
|
||||||
$self -> {"template"},
|
};
|
||||||
$self -> {"settings"},
|
foreach my $key (%{$self}) {
|
||||||
$self -> {"session"},
|
$args{$key} = $self -> {$key};
|
||||||
$self)
|
}
|
||||||
|
|
||||||
|
my $modobj = $name -> new(%args)
|
||||||
or set_error("Unable to load module: ".$Block::errstr);
|
or set_error("Unable to load module: ".$Block::errstr);
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
@ -234,7 +235,7 @@ sub build_sidebar {
|
|||||||
my $result = "";
|
my $result = "";
|
||||||
while(my $row = $sth -> fetchrow_hashref()) {
|
while(my $row = $sth -> fetchrow_hashref()) {
|
||||||
# Load the block module
|
# Load the block module
|
||||||
my $headerobj = $self -> new_module_byid($row -> {"module_id"},
|
my $headerobj = $self -> new_module_byid($row -> {"module_id"},
|
||||||
$row -> {"args"});
|
$row -> {"args"});
|
||||||
|
|
||||||
# If we have an object, ask it do generate its block display.
|
# If we have an object, ask it do generate its block display.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user