File Coverage

blib/lib/CGI/Session/Serialize/php.pm
Criterion Covered Total %
statement 28 32 87.5
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 38 44 86.3


line stmt bran cond sub pod time code
1             # Copyright (c) 2012 Ian McWilliam
2             #
3             # Permission to use, copy, modify, and distribute this software for any
4             # purpose with or without fee is hereby granted, provided that the above
5             # copyright notice and this permission notice appear in all copies.
6             #
7             # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8             # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9             # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10             # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11             # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12             # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13             # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14              
15             package CGI::Session::Serialize::php;
16              
17 1     1   7941 use strict;
  1         2  
  1         33  
18 1     1   6 use warnings;
  1         5  
  1         32  
19 1     1   6 use CGI::Session::ErrorHandler;
  1         3  
  1         30  
20 1     1   914 use PHP::Session::Serializer::PHP;
  1         3263  
  1         272  
21              
22             # Debug
23             #use Data::Dumper;
24              
25             @CGI::Session::Serialize::php::ISA = ('CGI::Session::ErrorHandler');
26             $CGI::Session::Serialize::php::VERSION = '1.1';
27              
28             sub freeze {
29 2     2 1 36161 my $self = shift;
30 2         4 my $data = shift;
31              
32 2         14 my $serializer = PHP::Session::Serializer::PHP->new();
33 2         22 my $serialized_string = '';
34              
35 2         4 eval {$serialized_string = $serializer->encode($data)};
  2         8  
36              
37 2 50       517 if ($@) {
38 0         0 $self->set_error('freeze(): Error decoding data : ' . "$@");
39 0         0 return(undef);
40             }
41              
42             # Debug
43             #warn($serialized_string);
44              
45 2         18 return($serialized_string);
46             }
47              
48             sub thaw {
49 1     1 1 1134 my $self = shift;
50 1         2 my $string = shift;
51              
52 1         8 my $serializer = PHP::Session::Serializer::PHP->new();
53 1         11 my $deserialized_data = {};
54              
55 1         3 eval {$deserialized_data = $serializer->decode($string)};
  1         6  
56              
57 1 50       709 if ($@) {
58 0         0 $self->set_error('thaw(): Error decoding data : ' . "$@");
59 0         0 return(undef);
60             }
61              
62             # Debug
63             #warn(Dumper($deserialized_data));
64              
65 1         6 return($deserialized_data);
66             }
67              
68             1;
69              
70             __END__;