knows how to read the permission string script and return
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Perm.pm
1 package OpenILS::Perm;
2 use strict; use warnings;
3 use Template qw(:template);
4 use OpenSRF::Utils::SettingsClient;
5 use OpenILS::Utils::Fieldmapper;
6 use OpenSRF::EX qw(:try);
7 use OpenSRF::AppSession;
8
9 # ----------------------------------------------------------------------------------
10 # These permission strings
11 # ----------------------------------------------------------------------------------
12
13 # returns a new fieldmapper::perm_ex
14
15 sub new {
16
17         my($class, $type) = @_;
18         $class = ref($class) || $class;
19
20         my $self = new Fieldmapper::perm_ex;
21
22         $self->err_msg(_find_perm_string($type));
23         $self->type($type);
24         warn "perm type is $type\n";
25         return $self;
26 }
27
28
29 sub _find_perm_string  {
30
31         my $type = shift;
32
33         my $result;
34         my $conf = OpenSRF::Utils::SettingsClient->new;
35
36         my $script = $conf->config_value("perm_script");
37
38         my $template = Template->new(
39                 { 
40                         ABSOLUTE                => 1, 
41                         OUTPUT          => \$result,
42                 }
43         );
44
45         my $status = $template->process($script, { type => $type });
46
47         if(!$status) {
48                 throw OpenSRF::EX::ERROR 
49                         ("Unable to process exception script.  No meaningful data to return..." .
50                         " Error is:\n" . $template->error() . "\n");
51         }
52
53         $result =~ s/^\s*//og;
54         warn " -|-|-|- Perm Exception result [$result]\n";
55
56         return $result;
57 }
58
59
60
61
62
63 1;