]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/EX.pm
5be7f66ac91fb9e92ceed956a54d115c768fd546
[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         PERMISSION_DENIED                                               => 7,
19         UNKNOWN_USER                                                    => 8, 
20 );
21
22 use overload ( '""' => sub { $_[0]->ex()->err_msg(); } );
23
24 sub new {
25
26         my($class, $type) = @_;
27         $class = ref($class) || $class;
28
29         my $self = {};
30         bless($self, $class);
31
32         $self->{ex} = new Fieldmapper::ex;
33         $self->{ex}->type($ex_types{$type});
34         $self->{ex}->err_msg($self->run());
35         warn "type is $type\n";
36
37         return $self;
38 }
39
40
41 sub ex { return shift()->{ex}; }
42
43 sub run {
44
45         my $self = shift;
46
47         my $result;
48         my $conf = OpenSRF::Utils::SettingsClient->new;
49
50         my $script = $conf->config_value("ex_script");
51
52         my $template = Template->new(
53                 { 
54                         ABSOLUTE                => 1, 
55                         OUTPUT          => \$result,
56                         PRE_CHOMP       => 1,
57                         POST_CHOMP      => 1,
58                 }
59         );
60
61         my $status = $template->process($script, 
62                         { ex_types => \%ex_types, type => $self->{ex}->type });
63
64         if(!$status) {
65                 return "Unable to process exception script.  No meaningful data to return..." .
66                         " Error is:\n" . $template->error() . "\n";
67         }
68
69         $result =~ s/^\s*//og;
70         warn " -|-|-|- Exception result [$result]\n";
71
72         return $result;
73 }
74
75
76
77
78
79