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

View File

@ -233,7 +233,7 @@ sub run {
phpbb => $self -> {"phpbb"},
modules => $self -> {"modules"},
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"});
}
@ -244,11 +244,11 @@ sub run {
# 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"})
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
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
my $content = $pageobj -> page_display();

10
Auth.pm
View File

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

View File

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

View File

@ -65,8 +65,8 @@ sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
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
# gets called, but even if it has, doing it again won't hurt anything).

View File

@ -29,6 +29,7 @@
package BlockSelector;
use strict;
use base qw(SystemModule);
# ============================================================================
@ -43,9 +44,9 @@ use strict;
sub new {
my $invocant = shift;
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;
}

View File

@ -61,15 +61,10 @@
# allow modifications made to configuration settings to be saved back into the table.
package ConfigMicro;
require 5.005;
use DBI;
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
@ -87,22 +82,19 @@ sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $filename = shift;
# Object constructors don't get much more minimal than this...
my $self = { "__privdata" => { "modified" => 0 },
@_,
};
my $obj = bless $self, $class;
my $self = $class -> SUPER::new(minimal => 1, # minimal tells SystemModule to skip object checks
"__privdata" => { "modified" => 0 },
@_)
or return undef;
# Return here if we have no filename to load from
return $obj if(!$filename);
return $self if(!$filename);
# 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
return set_error($obj -> {"errstr"});
return set_error($self -> {"errstr"});
}