1 package Maasha::BGB::Session;
3 # Copyright (C) 2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for session handling of the Biopieces Browser.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 use vars qw( @ISA @EXPORT );
41 @ISA = qw( Exporter );
44 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
49 # Martin A. Hansen, December 2009.
51 # Create a new session id which is md5 hashed.
57 $sid = Digest::MD5::md5_hex( Maasha::Common::get_sessionid() );
65 # Martin A. Hansen, December 2009.
67 # Parses a tab seperated session file and returns the data
68 # as a hash with user as key, and the rest of the columns as
71 my ( $file, # session file
76 my ( $fh, $json, $json_text, $session );
80 $fh = Maasha::Filesys::file_read_open( $file );
88 $session = $json->decode( $json_text );
90 return wantarray ? %{ $session } : $session;
96 # Martin A. Hansen, December 2009.
98 # Stores a session hash to file.
100 my ( $file, # file to store in.
101 $session, # session to store.
106 my ( $json, $json_text, $fh );
110 $json_text = $json->pretty->encode( $session );
112 $fh = Maasha::Filesys::file_write_open( $file );
114 print $fh $json_text;
120 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<