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