From 3393a242c5b4eac44b07bad8d7db5f4be3574a7e Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 9 May 2005 21:46:15 +0000 Subject: [PATCH] User level exceptions. the exception messages are stored in a template and are resurrected by defining the exception type in the constructor git-svn-id: svn://svn.open-ils.org/ILS/trunk@684 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/EX.pm | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Open-ILS/src/perlmods/OpenILS/EX.pm diff --git a/Open-ILS/src/perlmods/OpenILS/EX.pm b/Open-ILS/src/perlmods/OpenILS/EX.pm new file mode 100644 index 0000000000..9632d750d8 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/EX.pm @@ -0,0 +1,73 @@ +package OpenILS::EX; +use strict; use warnings; +use Template qw(:template); +use OpenSRF::Utils::SettingsClient; +use OpenILS::Utils::Fieldmapper; + +# ---------------------------------------------------------------------------------- +# These exceptions are not thrown. They are returned as request result objects +# ---------------------------------------------------------------------------------- + +my %ex_types = ( + UNKNOWN => 1, + SEARCH_TOO_LARGE => 2, +); + +use overload ( '""' => sub { $_[0]->ex()->err_msg(); } ); + +sub new { + + my($class, $type) = @_; + $class = ref($class) || $class; + + my $self = {}; + bless($self, $class); + + $self->{ex} = new Fieldmapper::ex; + $self->{ex}->type($ex_types{$type}); + $self->{ex}->err_msg($self->run()); + warn "type is $type\n"; + + return $self; +} + + +sub ex { return shift()->{ex}; } + +sub run { + + my $self = shift; + + my $result; + my $conf = OpenSRF::Utils::SettingsClient->new; + + my $script = $conf->config_value("ex_script"); + + my $template = Template->new( + { + ABSOLUTE => 1, + OUTPUT => \$result, + PRE_CHOMP => 1, + POST_CHOMP => 1, + } + ); + + my $status = $template->process($script, + { ex_types => \%ex_types, type => $self->{ex}->type }); + + if(!$status) { + return "Unable to process exception script. No meaningful data to return..." . + " Error is:\n" . $template->error() . "\n"; + } + + $result =~ s/^\s*//og; + warn " -|-|-|- Exception result [$result]\n"; + + return $result; +} + + + + + + -- 2.43.2