template accessible opensrf session class
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 11 May 2005 15:48:56 +0000 (15:48 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 11 May 2005 15:48:56 +0000 (15:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@700 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Template/Plugin/WebSession.pm [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/OpenILS/Template/Plugin/WebSession.pm b/Open-ILS/src/perlmods/OpenILS/Template/Plugin/WebSession.pm
new file mode 100644 (file)
index 0000000..dea5a67
--- /dev/null
@@ -0,0 +1,57 @@
+package OpenILS::Template::Plugin::WebSession;
+use strict; use warnings;
+use OpenILS::Utils::Fieldmapper;
+
+use Template::Plugin;
+use base qw/Template::Plugin/;
+use OpenSRF::AppSession;
+use OpenSRF::System;
+
+use vars qw/$textmap/;
+
+# allows us to use a process-wide variable cache
+my $_CACHE = {};
+
+sub gettext {
+       my( $self, $text ) = @_;
+       return $text;
+}
+
+sub new {
+       my ($class) = @_;
+       $class = ref($class) || $class;
+       my $self = {};
+       return bless($self,$class);
+}
+       
+my $bootstrapped = 0;
+sub bootstrap_client {
+       my( $self, $config_file ) = @_;
+       if(!$bootstrapped) {
+               OpenSRF::System->bootstrap_client( config_file => $config_file );
+               $bootstrapped = 1;
+       }
+}
+
+sub init_app_session {
+       my($self, $service) = @_;
+       return undef unless $service;
+       return OpenSRF::AppSession->create($service);
+}
+
+sub add_cache {
+       my($self, $key, $value ) = @_;
+       $_CACHE->{$key} = $value;
+}
+
+sub get_cache {
+       my( $self, $key ) = @_;
+       if( exists($_CACHE->{$key})) {
+               return $_CACHE->{$key};
+       }
+       return undef;
+}
+
+
+
+1;