]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/EX.pm
adding more exception types
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / EX.pm
1 package OpenILS::EX;
2 use strict; use warnings;
3 use Template qw(:template);
4 use OpenSRF::Utils::SettingsClient;
5 use OpenILS::Utils::Fieldmapper;
6
7 # ----------------------------------------------------------------------------------
8 # These exceptions are not thrown.  They are returned as request result objects
9 # ----------------------------------------------------------------------------------
10
11 my %ex_types = (
12         UNKNOWN                                                                 => 1,
13         SEARCH_TOO_LARGE                                                => 2,
14         UNKNOWN_BARCODE                                         => 3,
15         DUPLICATE_INVALID_USER_BARCODE  => 4,
16         DUPLICATE_USER_USERNAME                         => 5,
17         USER_WRONG_PASSWORD                                     => 6,
18 );
19
20 use overload ( '""' => sub { $_[0]->ex()->err_msg(); } );
21
22 sub new {
23
24         my($class, $type) = @_;
25         $class = ref($class) || $class;
26
27         my $self = {};
28         bless($self, $class);
29
30         $self->{ex} = new Fieldmapper::ex;
31         $self->{ex}->type($ex_types{$type});
32         $self->{ex}->err_msg($self->run());
33         warn "type is $type\n";
34
35         return $self;
36 }
37
38
39 sub ex { return shift()->{ex}; }
40
41 sub run {
42
43         my $self = shift;
44
45         my $result;
46         my $conf = OpenSRF::Utils::SettingsClient->new;
47
48         my $script = $conf->config_value("ex_script");
49
50         my $template = Template->new(
51                 { 
52                         ABSOLUTE                => 1, 
53                         OUTPUT          => \$result,
54                         PRE_CHOMP       => 1,
55                         POST_CHOMP      => 1,
56                 }
57         );
58
59         my $status = $template->process($script, 
60                         { ex_types => \%ex_types, type => $self->{ex}->type });
61
62         if(!$status) {
63                 return "Unable to process exception script.  No meaningful data to return..." .
64                         " Error is:\n" . $template->error() . "\n";
65         }
66
67         $result =~ s/^\s*//og;
68         warn " -|-|-|- Exception result [$result]\n";
69
70         return $result;
71 }
72
73
74
75
76
77