BREAKING CHANGE: fixing up internal references to webperl modules, pt 2.

This commit is contained in:
Chris 2012-12-23 18:26:38 +00:00
parent 5238d6ca1b
commit b8c2cb9ad9
26 changed files with 149 additions and 142 deletions

View File

@ -46,10 +46,10 @@
# to call the overridden methods this class via `$self -> SUPER::pre_authenticate()`
# or `$self -> SUPER::pre_authenticate()` to extend the default behaviour with
# system-specifics rather than entirely replacing it.
package AppUser;
package Webperl::AppUser;
use strict;
use base qw(SystemModule); # Extend SystemModule to get error handling
use base qw(Webperl::SystemModule); # Extend SystemModule to get error handling
use constant ANONYMOUS_ID => 1; # Default anonymous user id.
use constant ADMIN_TYPE => 3; # User type for admin users.
@ -57,8 +57,8 @@ use constant ADMIN_TYPE => 3; # User type for admin users.
# ============================================================================
# Constructor
## @cmethod AppUser new(%args)
# Create a new AppUser object. This will create an AppUser object that may be
## @cmethod Webperl::AppUser new(%args)
# Create a new Webperl::AppUser object. This will create a Webperl::AppUser object that may be
# passed to the Auth class to provide application-specific user handling.
#
# @param args A hash of arguments to initialise the AppUser object with.

View File

@ -23,11 +23,11 @@
# the developer needs to do is:
#
# use lib "/path/to/webperl";
# use lib "modules";
# use Application;
# use AppUser::MySystem; # Implemented in modules/AppUser/MySystem.pm
# use lib "/your/webapp/modules";
# use Webperl::Application;
# use Webperl::AppUser::MySystem; # Implemented in modules/Webperl/AppUser/MySystem.pm
#
# my $app = Application -> new(appuser => AppUser::MySystem -> new());
# my $app = Application -> new(appuser => Webperl::AppUser::MySystem -> new());
# $app -> run();
#
# In general, you will also want to load CGI::Carp and set it up, to handle
@ -36,7 +36,7 @@
# up as needed, this just simplifies the process. See the @ref overview Overview
# documentation for more details about the operation of this class.
#
package Application;
package Webperl::Application;
use strict;
@ -47,15 +47,15 @@ use Module::Load;
use Time::HiRes qw(time);
# Webperl modules
use Auth;
use BlockSelector;
use ConfigMicro;
use Logger;
use Template;
use SessionHandler;
use Modules;
use Message::Queue;
use Utils qw(path_join is_defined_numeric get_proc_size);
use Webperl::Auth;
use Webperl::BlockSelector;
use Webperl::ConfigMicro;
use Webperl::Logger;
use Webperl::Template;
use Webperl::SessionHandler;
use Webperl::Modules;
use Webperl::Message::Queue;
use Webperl::Utils qw(path_join is_defined_numeric get_proc_size);
our $errstr;
@ -67,29 +67,31 @@ BEGIN {
# ============================================================================
# Constructor
## @cmethod Application new(%args)
# Create a new Application object. This will create an Application object that
# can be used to generate the pages of a web application. Supported arguments
# are:
## @cmethod Webperl::Application new(%args)
# Create a new Webperl::Application object. This will create a Webperl::Application
# object that can be used to generate the pages of a web application. Supported
# arguments are:
#
# - `config`, the location of the application config file, defaults to `config/site.cfg`.
# If a relative path is provided, it is assumed to be relative to the index.cgi
# - `use_phpbb`, if set, the phpBB3 support module is loaded (and takes over auth: the
# `auth` argument is ignored if `use_phpbb` is set).
# - `appuser`, a reference to an AppUser subclass object to do application-specific
# - `appuser`, a reference to a Webperl::AppUser subclass object to do application-specific
# user tasks during auth. Can be omitted if use_phpbb is set.
# - `auth`, an optional reference to an auth object. If not specified, and `use_phpbb`
# is not set, an Auth object is made for you.
# - `block_selector`, an optional reference to a BlockSelector subclass. If not specified,
# the default BlockSelector is used instead to provide standard block selection behaviour.
# - `system`, an optional reference to a System object. If specified, the init() method
# in this module is called with a hash of arguments containing the database handle,
# is not set, a Webperl::Auth object is made for you.
# - `block_selector`, an optional reference to a Webperl::BlockSelector subclass. If not
# specified, the default Webperl::BlockSelector is used instead to provide standard
# block selection behaviour.
# - `system`, an optional reference to a Webperl::System object. If specified, the init()
# method in this module is called with a hash of arguments containing the database handle,
# cgi object, settings, session handler, template handler, and module loader.
# - `upload_hook`, an optional reference to a function to use as a CGI upload hook.
# - `post_max`, the maximum size of uploaded data in MB. If not set, the default is to
# limit posts to 128MB.
#
# @param args A hash of arguments to initialise the Application object with.
# @return A new Application object.
# @param args A hash of arguments to initialise the Webperl::Application object with.
# @return A new Webperl::Application object.
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
@ -116,11 +118,11 @@ sub run {
$self -> {"starttime"} = time();
$self -> {"logger"} = Logger -> new()
$self -> {"logger"} = Webperl::Logger -> new()
or die "FATAL: Unable to create logger object";
# Load the system config
$self -> {"settings"} = ConfigMicro -> new($self -> {"config"})
$self -> {"settings"} = Webperl::ConfigMicro -> new($self -> {"config"})
or $self -> {"logger"} -> die_log("Not avilable", "Application: Unable to obtain configuration file: ".$ConfigMicro::errstr);
# Create a new CGI object to generate page content through
@ -144,13 +146,13 @@ sub run {
$self -> {"logger"} -> start_log($self -> {"settings"} -> {"config"} -> {"logfile"}) if($self -> {"settings"} -> {"config"} -> {"logfile"});
# Message queue handling
$self -> {"messages"} = Message::Queue -> new(logger => $self -> {"logger"},
$self -> {"messages"} = Webperl::Message::Queue -> new(logger => $self -> {"logger"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create message handler: ".$SystemModule::errstr);
# Create the template handler object
$self -> {"template"} = Template -> new(logger => $self -> {"logger"},
$self -> {"template"} = Webperl::Template -> new(logger => $self -> {"logger"},
basedir => $self -> {"settings"} -> {"config"} -> {"template_dir"} || "templates",
timefmt => $self -> {"settings"} -> {"config"} -> {"timefmt"},
blockname => 1,
@ -160,8 +162,8 @@ sub run {
# If phpbb mode is enabled, it takes over auth.
if($self -> {"use_phpbb"}) {
load phpBB3;
$self -> {"phpbb"} = phpBB3 -> new(logger => $self -> {"logger"},
load Webperl::phpBB3;
$self -> {"phpbb"} = Webperl::phpBB3 -> new(logger => $self -> {"logger"},
prefix => $self -> {"settings"} -> {"database"} -> {"phpbb_prefix"},
cgi => $self -> {"cgi"},
data_src => $self -> {"settings"} -> {"database"} -> {"phpbb_database"},
@ -179,14 +181,14 @@ sub run {
$self -> {"appuser"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"settings"}, $self -> {"logger"});
# If the auth object is not set, make one
$self -> {"auth"} = Auth -> new() if(!$self -> {"auth"});
$self -> {"auth"} = Webperl::Auth -> new() if(!$self -> {"auth"});
# Initialise the auth object
$self -> {"auth"} -> init($self -> {"cgi"}, $self -> {"dbh"}, $self -> {"appuser"}, $self -> {"settings"}, $self -> {"logger"});
}
# Start the session engine...
$self -> {"session"} = SessionHandler -> new(logger => $self -> {"logger"},
$self -> {"session"} = Webperl::SessionHandler -> new(logger => $self -> {"logger"},
cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
auth => $self -> {"auth"},
@ -209,7 +211,7 @@ sub run {
}
# And now we can make the module handler
$self -> {"modules"} = Modules -> new(logger => $self -> {"logger"},
$self -> {"modules"} = Webperl::Modules -> new(logger => $self -> {"logger"},
cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"},
@ -239,7 +241,7 @@ sub run {
}
# Has a block selector been specified? If not, make a default one
$self -> {"block_selector"} = BlockSelector -> new()
$self -> {"block_selector"} = Webperl::BlockSelector -> new()
if(!defined($self -> {"block_selector"}));
# Obtain the page moduleid, fall back on the default if this fails

View File

@ -26,15 +26,15 @@
#
# This class requires an entry in the settings table with the name 'Auth:unique_id',
# and settings as required by SessionHandler.
package Auth;
package Webperl::Auth;
use strict;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
use HTML::Entities;
# Custom module imports
use AuthMethods;
use Webperl::AuthMethods;
# ============================================================================
# Constructor
@ -92,12 +92,12 @@ sub init {
return "logger object not set" unless($self -> {"logger"});
# Create the authmethods object to handle invocation of individual methods
$self -> {"methods"} = AuthMethods -> new(cgi => $self -> {"cgi"},
$self -> {"methods"} = Webperl::AuthMethods -> new(cgi => $self -> {"cgi"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"},
app => $self -> {"app"},
logger => $self -> {"logger"})
or return "Unable to create AuthMethods object: ".$AuthMethods::errstr;
or return "Unable to create Webperl::AuthMethods object: ".$Webperl::AuthMethods::errstr;
$self -> {"ANONYMOUS"} = $self -> {"app"} -> anonymous_user();
$self -> {"ADMINTYPE"} = $self -> {"app"} -> adminuser_type();

View File

@ -21,7 +21,7 @@
# mainly present for documentation purposes - it doesn't actually provide
# any meaningful implementation of an authentication method, and the
# actually interesting stuff should happen in subclasses of it.
package AuthMethod;
package Webperl::AuthMethod;
use strict;

View File

@ -35,10 +35,10 @@
#
# * bcrypt_cost - the number of iterations of hashing to perform. This
# defaults to COST_DEFAULT if not specified.
package AuthMethod::Database;
package Webperl::AuthMethod::Database;
use strict;
use base qw(AuthMethod); # This class extends AuthMethod
use base qw(Webperl::AuthMethod); # This class extends AuthMethod
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
use constant COST_DEFAULT => 14; # The default cost to use if bcrypt_cost is not set.
@ -67,9 +67,9 @@ sub new {
$self -> {"bcrypt_cost"} = COST_DEFAULT;
# check that required settings are set...
return "AuthMethod::Database missing 'table' argument in new()" if(!$self -> {"table"});
return "AuthMethod::Database missing 'userfield' argument in new()" if(!$self -> {"userfield"});
return "AuthMethod::Database missing 'passfield' argument in new()" if(!$self -> {"passfield"});
return "Webperl::AuthMethod::Database missing 'table' argument in new()" if(!$self -> {"table"});
return "Webperl::AuthMethod::Database missing 'userfield' argument in new()" if(!$self -> {"userfield"});
return "Webperl::AuthMethod::Database missing 'passfield' argument in new()" if(!$self -> {"passfield"});
return $self;
}

View File

@ -36,10 +36,10 @@
# * adminpass - The password to use when logging in as the admin user.
# * reuseconn - If set to a true value, the connection to the LDAPS is reused
# for authentication after finding the user's dn.
package AuthMethod::LDAPS;
package Webperl::AuthMethod::LDAPS;
use strict;
use base qw(AuthMethod); # This class extends AuthMethod
use base qw(Webperl::AuthMethod); # This class extends AuthMethod
use Net::LDAPS;
## @cmethod $ new(%args)
@ -59,9 +59,9 @@ sub new {
return $class -> SUPER::get_error() if(!$self);
# check that required settings are set...
return "AuthMethod::LDAPS missing 'server' argument in new()" if(!$self -> {"server"});
return "AuthMethod::LDAPS missing 'base' argument in new()" if(!$self -> {"base"});
return "AuthMethod::LDAPS missing 'searchfield' argument in new()" if(!$self -> {"searchfield"});
return "Webperl::AuthMethod::LDAPS missing 'server' argument in new()" if(!$self -> {"server"});
return "Webperl::AuthMethod::LDAPS missing 'base' argument in new()" if(!$self -> {"base"});
return "Webperl::AuthMethod::LDAPS missing 'searchfield' argument in new()" if(!$self -> {"searchfield"});
return $self;
}

View File

@ -34,10 +34,10 @@
# specified (values less than 5 are only recommended on fast
# networks and when talking to servers that respond rapidly).
# * binary - the location of the ssh binary. Defaults to /usr/bin/ssh.
package AuthMethod::SSH;
package Webperl::AuthMethod::SSH;
use strict;
use base qw(AuthMethod); # This class extends AuthMethod
use base qw(Webperl::AuthMethod); # This class extends AuthMethod
use Net::SSH::Expect;
# Custom module imports
@ -61,7 +61,7 @@ sub new {
return $class -> SUPER::get_error() if(!$self);
# check that required settings are set...
return "AuthMethod::SSH missing 'server' argument in new()" if(!$self -> {"server"});
return "Webperl::AuthMethod::SSH missing 'server' argument in new()" if(!$self -> {"server"});
# Check whether the timeout and binary settings are, well, set...
$self -> {"timeout"} = 5 unless(defined($self -> {"timeout"}));

View File

@ -22,10 +22,10 @@
# on information stored in the auth_methods and auth_params tables to
# load AuthMethod subclasses, initialise them, and pass them back to
# the caller to use.
package AuthMethods;
package Webperl::AuthMethods;
use strict;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
use Module::Load;
# ============================================================================

View File

@ -29,12 +29,12 @@
# which may be generated solely by the Block subclass, or by the subclass
# loading other Blocks and using their inline block fragments to construct the
# overall page content.
package Block;
package Webperl::Block;
use strict;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
use HTMLValidator;
use Utils qw(is_defined_numeric);
use Webperl::HTMLValidator;
use Webperl::Utils qw(is_defined_numeric);
use Encode;
use HTML::Entities;

View File

@ -26,10 +26,10 @@
# and valid, or falls back on a default block id otherwise. Other
# applications may wish to extend this behaviour, or replace it entirely
# by subclassing this class and overriding the get_block() method.
package BlockSelector;
package Webperl::BlockSelector;
use strict;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
# ============================================================================

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class ConfigMicro
## @class
# A simple configuration class intended to allow ini files to be read and saved. This
# class reads the contents of an .ini style file, and stores the sections and
# key/value pairs in the object's hash. A typical configuration file could look like
@ -59,10 +59,10 @@
# load_db_config() method in any ConfigMicro object allows a table containing key/value
# pairs to be read into a configuration section. save_db_config() and set_db_config()
# allow modifications made to configuration settings to be saved back into the table.
package ConfigMicro;
package Webperl::ConfigMicro;
use strict;
use base qw(SystemModule); # Extend SystemModule to get error handling
use base qw(Webperl::SystemModule); # Extend SystemModule to get error handling
use DBI;
@ -70,14 +70,14 @@ use DBI;
# Constructor and basic file-based config functions
## @cmethod $ new(%args)
# Create a new ConfigMicro object. This creates an object that provides functions
# Create a new Webperl::ConfigMicro object. This creates an object that provides functions
# for loading and saving configurations, and pulling config data from a database.
# Meaningful options for this are:
# filename - The name of the configuration file to read initial settings from. This
# is optional, and if not specified you will get an empty object back.
# You may also pass in one or more initial configuration settings.
# @param args A hash of key, value pairs to initialise the object with.
# @return A new ConfigMicro object, or undef if a problem occured.
# @return A new Webperl::ConfigMicro object, or undef if a problem occured.
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;

View File

@ -19,7 +19,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package HTMLValidator;
package Webperl::HTMLValidator;
require Exporter;
use Encode;

View File

@ -22,7 +22,7 @@
# together the various functions needed for displaying log messages and errors
# at various levels of verbosity, in an attempt to cut down on duplicate
# parameter passing throughout the rest of the system.
package Logger;
package Webperl::Logger;
use strict;
require Exporter;

View File

@ -27,13 +27,13 @@
# need the full features of MediaWiki::Bot, you can obtain a reference to a
# MediaWiki::API object to issue API requests directly to by calling the wiki()
# function.
package MediaWiki::Simple;
package Webperl::MediaWiki::Simple;
use v5.12;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
use Data::Dumper;
use MediaWiki::API;
use Utils qw(path_join);
use Webperl::Utils qw(path_join);
# ============================================================================
# Constructor

View File

@ -19,10 +19,10 @@
## @class Message
# This is the 'base' class for the Message modules. It provides any functionality
# that needs to be shared between the Message::* modules.
package Message;
package Webperl::Message;
use strict;
use base qw(SystemModule);
use Utils qw(hash_or_hashref);
use base qw(Webperl::SystemModule);
use Webperl::Utils qw(hash_or_hashref);
# ============================================================================
# Constructor

View File

@ -16,15 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class Message::Queue
## @class
# This class allows messages to be added to the message queue, or retrieved from
# it in a format suitable for passing to Message::Sender.
#
#
package Message::Queue;
package Webperl::Message::Queue;
use strict;
use base qw(Message);
use Utils qw(hash_or_hashref);
use base qw(Webperl::Message);
use Webperl::Utils qw(hash_or_hashref);
# ============================================================================
# Constructor

View File

@ -16,13 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class Message::Transport
## @class
# This is the 'base' class for the Message::Transport modules. It provides
# any functionality that needs to be shared between the Message::Transport::*
# modules.
package Message::Transport;
package Webperl::Message::Transport;
use strict;
use base qw(Message);
use base qw(Webperl::Message);
# ============================================================================
# Delivery

View File

@ -16,12 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class Message::Transport::Email
## @class
# This class implements the email transport system; lasciate ogne speranza, voi ch'intrate.
#
package Message::Transport::Email;
package Webperl::Message::Transport::Email;
use strict;
use base qw(Message::Transport);
use base qw(Webperl::Message::Transport);
use Encode;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);

View File

@ -16,13 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class Message::Transport::Local
## @class
# This class implements the local delivery transport. Local delivery actually involves
# no work whatsoever - any messages that are queued for local deliver can always be
# delivered.
package Message::Transport::Local;
package Webperl::Message::Transport::Local;
use strict;
use base qw(Message::Transport);
use base qw(Webperl::Message::Transport);
# ============================================================================
# Delivery

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## @class Modules
## @class
# A class to simplify runtime loading of modules. This class simplifies the
# process of loading modules implementing system functionality at runtime: it
# is primarily designed to load webapp block modules, but it can be used to
@ -53,11 +53,12 @@
# the contents of the Modules object's $self added to it, so that your loaded
# modules will be given the standard value listed above in addition to any
# values you specify in the argument hash.
package Modules;
package Webperl::Modules;
use strict;
use base qw(SystemModule);
use DBI;
use base qw(Webperl::SystemModule);
use Module::Load;
use Webperl::Utils qw(path_join);
# ==============================================================================
# Creation
@ -112,6 +113,10 @@ sub add_load_path {
my $self = shift;
my $path = shift;
# If the load path is relative, assume it is relative to the script base path
$path = path_join($self -> {"settings"} -> {"config"} -> {"base"}, $path)
unless($path =~ m|^/|);
unshift(@INC, $path);
}

View File

@ -124,19 +124,15 @@
# KEY `session_id` (`session_id`),
# KEY `sess_name_map` (`session_id`,`var_name`)
# ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Session-related variables';
package SessionHandler;
package Webperl::SessionHandler;
require 5.005;
use strict;
# Standard module imports
use DBI;
use Digest::MD5 qw(md5_hex);
use Compress::Bzip2;
use MIME::Base64;
use Data::Dumper;
# Globals...
our $errstr;

View File

@ -21,10 +21,10 @@
# The base class for appplication-specific module loading. Subclasses of
# this class allow applications to load and initialise any system-specific
# modules.
package System;
package Webperl::System;
use strict;
use base qw(SystemModule);
use base qw(Webperl::SystemModule);
# ============================================================================
# Constructor and initialiser

View File

@ -22,7 +22,7 @@
# Subclasses will generally only need to override the constructor, usually
# chaining it with `$class -> SUPER::new(..., @_);`. If attempting to call
# set_error() in a subclass, remember to use SystemModule::set_error().
package SystemModule;
package Webperl::SystemModule;
use strict;

View File

@ -114,10 +114,10 @@
# - `{V_[commonpath]}` is replaced by the path from the base of the web
# application to the common template directory (useful for image and other resource
# paths inside the common template). This will always have a trailing '/'.
package Template;
package Webperl::Template;
use POSIX qw(strftime);
use Utils qw(path_join superchomp);
use Webperl::Utils qw(path_join superchomp);
use strict;
our ($errstr, $utfentities, $entities, $ords, @timescales);

View File

@ -22,7 +22,7 @@
# System-wide utility functions. The functions in this file may be useful at
# any point throughout the system, so they are collected here to prevent the
# need for multiple copies around various modules.
package Utils;
package Webperl::Utils;
require Exporter;
use File::Spec;
use File::Path;

View File

@ -28,7 +28,7 @@
# into a phpBB3 account.
#
#
package phpBB3;
package Webperl::phpBB3;
use strict;
@ -39,7 +39,7 @@ use Time::HiRes qw(gettimeofday);
use WWW::Mechanize; # Needed to register via phpBB's registration form
# Custom module imports
use Utils qw(path_join);
use Webperl::Utils qw(path_join);
# Globals...
our ($ANONYMOUS, $errstr, %fmt_map);