« blib/lib/Lemonldap/NG/Common/Conf/Backends/SOAP.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/PSGI/SOAPServer.pm »
| 1 | package Lemonldap::NG::Common::Apache::Session::Serialize::JSON; | ||||||||||||
| 2 | |||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 7 | ▶ | use JSON qw(to_json from_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 7 | our $VERSION = '2.19.0'; | |||||||||||
| 7 | |||||||||||||
| 8 | 150 | ▶ | sub serialize { | ||||||||||
|
Subroutine
serialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 9 | 150 | my $session = shift; | |||||||||||
| 10 | |||||||||||||
| 11 | 150 | $session->{serialized} = to_json( $session->{data}, { allow_nonref => 1 } ); | |||||||||||
| 12 | } | ||||||||||||
| 13 | |||||||||||||
| 14 | 124 | ▶ | sub unserialize { | ||||||||||
|
Subroutine
unserialize: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 15 | 124 | my $session = shift; | |||||||||||
| 16 | |||||||||||||
| 17 | 124 | my $data = _unserialize( $session->{serialized} ); | |||||||||||
| 18 | 124 | ▶ | die "Session could not be unserialized" unless defined $data; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 124 | $session->{data} = $data; | |||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 0 | ▶ | sub unserializeBase64 { | ||||||||||
|
Subroutine
unserializeBase64: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 23 | 0 | my $session = shift; | |||||||||||
| 24 | |||||||||||||
| 25 | 0 | my $data = _unserialize( $session->{serialized}, \&decodeThaw64 ); | |||||||||||
| 26 | 0 | ▶ | die "Session could not be unserialized" unless defined $data; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 0 | $session->{data} = $data; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | sub decodeThaw64 { | ||||||||||
|
Subroutine
decodeThaw64: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 31 | 0 | require MIME::Base64; | |||||||||||
| 32 | 0 | my $s = shift; | |||||||||||
| 33 | 0 | return Storable::thaw( MIME::Base64::decode_base64($s) ); | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 261 | ▶ | sub _unserialize { | ||||||||||
|
Subroutine
_unserialize: called CC=4 SCAR=20.3
| |||||||||||||
| 37 | 261 | my ( $serialized, $next ) = @_; | |||||||||||
| 38 | 261 | my $tmp; | |||||||||||
| 39 | 261 | eval { $tmp = from_json( $serialized, { allow_nonref => 1 } ) }; | |||||||||||
| 40 | 261 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | eval { | |||||||||||
| 42 | 0 | require Storable; | |||||||||||
| 43 | 0 | ▶ | $next ||= \&Storable::thaw; | ||||||||||
|
Condition0%0/2
$next ||= \&Storable::thaw
MC/DC0%0/1
$next ||= \&Storable::thaw
$next
Truth table0%0/2
A
A= $next
| |||||||||||||
| 44 | 0 | return &$next($serialized); | |||||||||||
| 45 | }; | ||||||||||||
| 46 | 0 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | |||||||||||||
| 48 | # Error is catched in unserialize | ||||||||||||
| 49 | 0 | return undef; | |||||||||||
| 50 | } | ||||||||||||
| 51 | } | ||||||||||||
| 52 | 261 | return $tmp; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 7 | 1; | |||||||||||
| 56 | |||||||||||||
| 57 | =pod | ||||||||||||
| 58 | |||||||||||||
| 59 | =head1 NAME | ||||||||||||
| 60 | |||||||||||||
| 61 | =encoding utf8 | ||||||||||||
| 62 | |||||||||||||
| 63 | Lemonldap::NG::Common::Apache::Session::Serialize::JSON - Use JSON to zip up data | ||||||||||||
| 64 | |||||||||||||
| 65 | =head1 SYNOPSIS | ||||||||||||
| 66 | |||||||||||||
| 67 | use Lemonldap::NG::Common::Apache::Session::Serialize::JSON; | ||||||||||||
| 68 | |||||||||||||
| 69 | $zipped = Lemonldap::NG::Common::Apache::Session::Serialize::JSON::serialize($ref); | ||||||||||||
| 70 | $ref = Lemonldap::NG::Common::Apache::Session::Serialize::JSON::unserialize($zipped); | ||||||||||||
| 71 | |||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||
| 73 | |||||||||||||
| 74 | This module fulfills the serialization interface of Apache::Session. | ||||||||||||
| 75 | It serializes the data in the session object by use of JSON C<to_json> | ||||||||||||
| 76 | and C<from_json>. The serialized data is UTF-8 text. | ||||||||||||
| 77 | |||||||||||||
| 78 | |||||||||||||
| 79 | =head1 SEE ALSO | ||||||||||||
| 80 | |||||||||||||
| 81 | L<JSON>, L<Apache::Session> | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 AUTHORS | ||||||||||||
| 84 | |||||||||||||
| 85 | =over | ||||||||||||
| 86 | |||||||||||||
| 87 | =item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> | ||||||||||||
| 88 | |||||||||||||
| 89 | =item François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt> | ||||||||||||
| 90 | |||||||||||||
| 91 | =item Xavier Guimard, E<lt>x.guimard@free.frE<gt> | ||||||||||||
| 92 | |||||||||||||
| 93 | =item Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt> | ||||||||||||
| 94 | |||||||||||||
| 95 | =back | ||||||||||||
| 96 | |||||||||||||
| 97 | =head1 BUG REPORT | ||||||||||||
| 98 | |||||||||||||
| 99 | Use OW2 system to report bug or ask for features: | ||||||||||||
| 100 | L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues> | ||||||||||||
| 101 | |||||||||||||
| 102 | =head1 DOWNLOAD | ||||||||||||
| 103 | |||||||||||||
| 104 | Lemonldap::NG is available at | ||||||||||||
| 105 | L<https://lemonldap-ng.org/download> | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 108 | |||||||||||||
| 109 | =over | ||||||||||||
| 110 | |||||||||||||
| 111 | =item Copyright (C) 2015-2016 by Clément Oudot, E<lt>clem.oudot@gmail.comE<gt> | ||||||||||||
| 112 | |||||||||||||
| 113 | =item Copyright (C) 2015-2016 by Xavier Guimard, E<lt>x.guimard@free.frE<gt> | ||||||||||||
| 114 | |||||||||||||
| 115 | =back | ||||||||||||
| 116 | |||||||||||||
| 117 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 118 | it under the terms of the GNU General Public License as published by | ||||||||||||
| 119 | the Free Software Foundation; either version 2, or (at your option) | ||||||||||||
| 120 | any later version. | ||||||||||||
| 121 | |||||||||||||
| 122 | This program is distributed in the hope that it will be useful, | ||||||||||||
| 123 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 124 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||
| 125 | GNU General Public License for more details. | ||||||||||||
| 126 | |||||||||||||
| 127 | You should have received a copy of the GNU General Public License | ||||||||||||
| 128 | along with this program. If not, see L<http://www.gnu.org/licenses/>. | ||||||||||||
| 129 | |||||||||||||
| 130 | =cut | ||||||||||||