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