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