User level exceptions. the exception messages are stored in a
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 21:46:15 +0000 (21:46 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 21:46:15 +0000 (21:46 +0000)
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 [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/OpenILS/EX.pm b/Open-ILS/src/perlmods/OpenILS/EX.pm
new file mode 100644 (file)
index 0000000..9632d75
--- /dev/null
@@ -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;
+}
+
+
+
+
+
+