Serialize/JSON.pm

filter: Statementstmt 86.9% 20 / 23 Branchbran 50.0% 2 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 72.9% 27 / 37 CC 4 SCAR 8.5
CC
4
Cov
76%
_unserialize
3.9
unserialize
2.0
BEGIN
1.0
CRAP 2.3
« Browseable/Store/DBI.pm ↑ Summary Generate/SHA256.pm »
1 # Directly copied from Lemonldap::NG project (http://lemonldap-ng.org/)
2 package Apache::Session::Serialize::JSON;
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use JSON qw(to_json from_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 our $VERSION = '1.2.6';
8  
9 114 ▶sub serialize {
Subroutine serialize: called CC=1 SCAR=0.0
Pod undocumented
10 114 my $session = shift;
11  
12 114 $session->{serialized} = to_json( $session->{data}, { allow_nonref => 1 } );
13 }
14  
15 148 ▶sub unserialize {
Subroutine unserialize: called CC=2 SCAR=7.0
Pod undocumented
16 148 my ( $session, $next ) = @_;
17  
18 148 my $data = _unserialize( $session->{serialized}, $next );
19 148 ▶ die "Session could not be unserialized" unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 148 148
20 148 $session->{data} = $data;
21 }
22  
23 456 ▶sub _unserialize {
Subroutine _unserialize: called CC=3 SCAR=13.6
24 456 my ( $serialized, $next ) = @_;
25 456 my $tmp;
26 456 eval { $tmp = from_json( $serialized, { allow_nonref => 1 } ) };
27 456 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 456 456
28 0 require Storable;
29 0 ▶ $next ||= \&Storable::thaw;
Condition0%0/2
$next ||= \&Storable::thaw
l!l
00
MC/DC0%0/1
$next ||= \&Storable::thaw
$next
Truth table0%0/2
A
A= $next
Aresult
11
00
30 0 return &$next($serialized);
31 }
32 456 return $tmp;
33 }
34  
35 5 1;
36  
37 =pod
38  
39 =head1 NAME
40  
41 =encoding utf8
42  
43 Apache::Session::Serialize::JSON - Use JSON to zip up data
44  
45 =head1 SYNOPSIS
46  
47 use Apache::Session::Serialize::JSON;
48  
49 $zipped = Apache::Session::Serialize::JSON::serialize($ref);
50 $ref = Apache::Session::Serialize::JSON::unserialize($zipped);
51  
52 =head1 DESCRIPTION
53  
54 This module fulfills the serialization interface of Apache::Session.
55 It serializes the data in the session object by use of JSON C<to_json>
56 and C<from_json>. The serialized data is UTF-8 text.
57  
58  
59 =head1 SEE ALSO
60  
61 L<JSON>, L<Apache::Session>
62  
63 =head1 BUG REPORT
64  
65 Use OW2 system to report bug or ask for features:
66 L<http://jira.ow2.org>
67  
68 =head1 COPYRIGHT AND LICENSE
69  
70 =over
71  
72 =item 2009-2025 by Xavier Guimard
73  
74 =item 2013-2025 by Clément Oudot
75  
76 =item 2019-2025 by Maxime Besson
77  
78 =item 2013-2025 by Worteks
79  
80 =item 2023-2025 by Linagora
81  
82 =back
83  
84 This library is free software; you can redistribute it and/or modify
85 it under the terms of the GNU General Public License as published by
86 the Free Software Foundation; either version 2, or (at your option)
87 any later version.
88  
89 This program is distributed in the hope that it will be useful,
90 but WITHOUT ANY WARRANTY; without even the implied warranty of
91 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92 GNU General Public License for more details.
93  
94 You should have received a copy of the GNU General Public License
95 along with this program. If not, see L<http://www.gnu.org/licenses/>.
96  
97 =cut
« Browseable/Store/DBI.pm ↑ Summary Generate/SHA256.pm »