use strict;
use Data::Dumper;
use Digest::MD5;
+use JSON;
use Maasha::Common;
use Maasha::Filesys;
# Returns a hashref.
- my ( $fh, $line, $user, $password, $sid, $time, %session );
+ my ( $fh, $json, $json_text, $session );
+
+ local $/ = undef;
$fh = Maasha::Filesys::file_read_open( $file );
- while ( $line = <$fh> )
- {
- chomp $line;
+ $json_text = <$fh>;
- ( $user, $password, $sid, $time ) = split /\t/, $line;
+ close $fh;
- $session{ $user } = {
- PASSWORD => $password,
- SESSION_ID => $sid,
- TIME => $time,
- };
- }
+ $json = new JSON;
- close $fh;
+ $session = $json->decode( $json_text );
- return wantarray ? %session : \%session;
+ return wantarray ? %{ $session } : $session;
}
# Returns nothing.
- my ( $fh, $user );
+ my ( $json, $json_text, $fh );
+
+ $json = new JSON;
+
+ $json_text = $json->pretty->encode( $session );
$fh = Maasha::Filesys::file_write_open( $file );
- foreach $user ( keys %{ $session } )
- {
- print $fh join(
- "\t",
- $user,
- $session->{ $user }->{ 'PASSWORD' },
- $session->{ $user }->{ 'SESSION_ID' },
- $session->{ $user }->{ 'TIME' }
- ), "\n";
- }
+ print $fh $json_text;
close $fh;
}
1;
+
+__END__