]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Template/Plugin/WebSession.pm
template accessible opensrf session class
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Template / Plugin / WebSession.pm
1 package OpenILS::Template::Plugin::WebSession;
2 use strict; use warnings;
3 use OpenILS::Utils::Fieldmapper;
4
5 use Template::Plugin;
6 use base qw/Template::Plugin/;
7 use OpenSRF::AppSession;
8 use OpenSRF::System;
9
10 use vars qw/$textmap/;
11
12 # allows us to use a process-wide variable cache
13 my $_CACHE = {};
14
15 sub gettext {
16         my( $self, $text ) = @_;
17         return $text;
18 }
19
20 sub new {
21         my ($class) = @_;
22         $class = ref($class) || $class;
23         my $self = {};
24         return bless($self,$class);
25 }
26         
27 my $bootstrapped = 0;
28 sub bootstrap_client {
29         my( $self, $config_file ) = @_;
30         if(!$bootstrapped) {
31                 OpenSRF::System->bootstrap_client( config_file => $config_file );
32                 $bootstrapped = 1;
33         }
34 }
35
36 sub init_app_session {
37         my($self, $service) = @_;
38         return undef unless $service;
39         return OpenSRF::AppSession->create($service);
40 }
41
42 sub add_cache {
43         my($self, $key, $value ) = @_;
44         $_CACHE->{$key} = $value;
45 }
46
47 sub get_cache {
48         my( $self, $key ) = @_;
49         if( exists($_CACHE->{$key})) {
50                 return $_CACHE->{$key};
51         }
52         return undef;
53 }
54
55
56
57 1;