More modules moved to using SystemModule as their base for error

handling.
This commit is contained in:
Chris 2012-12-06 15:05:18 +00:00
parent f2e6403ee0
commit d53c875980
7 changed files with 28 additions and 40 deletions

View File

@ -66,13 +66,11 @@ use constant ADMIN_TYPE => 3; # User type for admin users.
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
# Note this doesn't use the superclass constructor, as it may be called before my $self = $class -> SUPER::new(minimal => 1, # minimal tells SystemModule to skip object checks
# the objects the superclass checks for are acutally available @_)
my $self = { or return undef;
@_,
};
return bless $self, $class; return $self;
} }

View File

@ -233,7 +233,7 @@ sub run {
phpbb => $self -> {"phpbb"}, phpbb => $self -> {"phpbb"},
modules => $self -> {"modules"}, modules => $self -> {"modules"},
messages => $self -> {"messages"}) messages => $self -> {"messages"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create system object: ".$self -> {"system"} -> {"errstr"}); or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create system object: ".$self -> {"system"} -> errstr());
$self -> {"appuser"} -> set_system($self -> {"system"}) if($self -> {"appuser"}); $self -> {"appuser"} -> set_system($self -> {"system"}) if($self -> {"appuser"});
} }
@ -244,11 +244,11 @@ sub run {
# Obtain the page moduleid, fall back on the default if this fails # Obtain the page moduleid, fall back on the default if this fails
my $pageblock = $self -> {"block_selector"} -> get_block($self -> {"dbh"}, $self -> {"cgi"}, $self -> {"settings"}, $self -> {"logger"}, $self -> {"session"}) my $pageblock = $self -> {"block_selector"} -> get_block($self -> {"dbh"}, $self -> {"cgi"}, $self -> {"settings"}, $self -> {"logger"}, $self -> {"session"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to determine page block: ".$self -> {"block_selector"} -> {"errstr"}); or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to determine page block: ".$self -> {"block_selector"} -> errstr());
# Obtain an instance of the page module # Obtain an instance of the page module
my $pageobj = $self -> {"modules"} -> new_module($pageblock) my $pageobj = $self -> {"modules"} -> new_module($pageblock)
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to load page module $pageblock: ".$self -> {"modules"} -> {"errstr"}); or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to load page module $pageblock: ".$self -> {"modules"} -> errstr());
# And call the page generation function of the page module # And call the page generation function of the page module
my $content = $pageobj -> page_display(); my $content = $pageobj -> page_display();

10
Auth.pm
View File

@ -55,13 +55,11 @@ use AuthMethods;
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
# Note this doesn't use the superclass constructor, as it may be called before my $self = $class -> SUPER::new(minimal => 1, # minimal tells SystemModule to skip object checks
# the objects the superclass checks for are acutally available @_)
my $self = { or return undef;
@_,
};
return bless $self, $class; return $self;
} }

View File

@ -40,9 +40,8 @@ use Module::Load;
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
my $self = $class -> SUPER::new(@_); my $self = $class -> SUPER::new(@_)
or return undef;
return undef if(!$self);
# Ensure that we have objects that we need # Ensure that we have objects that we need
return SystemModule::set_error("cgi object not set") unless($self -> {"cgi"}); return SystemModule::set_error("cgi object not set") unless($self -> {"cgi"});

View File

@ -65,8 +65,8 @@ sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
my $self = $class -> SUPER::new("logtable" => "", my $self = $class -> SUPER::new("logtable" => "",
@_); @_)
return undef if(!$self); or return undef;
# Set up the logger, if needed (Application usually does this long before the Block constructor # Set up the logger, if needed (Application usually does this long before the Block constructor
# gets called, but even if it has, doing it again won't hurt anything). # gets called, but even if it has, doing it again won't hurt anything).

View File

@ -29,6 +29,7 @@
package BlockSelector; package BlockSelector;
use strict; use strict;
use base qw(SystemModule);
# ============================================================================ # ============================================================================
@ -43,9 +44,9 @@ use strict;
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
my $self = { my $self = $class -> SUPER::new(minimal => 1, # minimal tells SystemModule to skip object checks
@_, @_)
}; or return undef;
return bless $self, $class; return bless $self, $class;
} }

View File

@ -61,15 +61,10 @@
# allow modifications made to configuration settings to be saved back into the table. # allow modifications made to configuration settings to be saved back into the table.
package ConfigMicro; package ConfigMicro;
require 5.005;
use DBI;
use strict; use strict;
use base qw(SystemModule); # Extend SystemModule to get error handling
use DBI;
our $errstr;
BEGIN {
$errstr = '';
}
# ============================================================================ # ============================================================================
# Constructor and basic file-based config functions # Constructor and basic file-based config functions
@ -87,22 +82,19 @@ sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
my $filename = shift; my $filename = shift;
my $self = $class -> SUPER::new(minimal => 1, # minimal tells SystemModule to skip object checks
# Object constructors don't get much more minimal than this... "__privdata" => { "modified" => 0 },
my $self = { "__privdata" => { "modified" => 0 }, @_)
@_, or return undef;
};
my $obj = bless $self, $class;
# Return here if we have no filename to load from # Return here if we have no filename to load from
return $obj if(!$filename); return $self if(!$filename);
# Otherwise, try to read the file # Otherwise, try to read the file
return $obj if($obj -> read($filename)); return $self if($self -> read($filename));
# Get here and things have gone wahoonie-shaped # Get here and things have gone wahoonie-shaped
return set_error($obj -> {"errstr"}); return set_error($self -> {"errstr"});
} }