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