File: MongoDB.pm

package info (click to toggle)
libapache-session-mongodb-perl 0.23-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: perl: 141; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Apache::Session::Serialize::MongoDB;

use 5.010;
use strict;

our $VERSION = '0.16';

sub serialize {
    my $session = shift;
    &replaceSpecialCharacters( $session->{data} );
}

sub unserialize {
    my $session = shift;
    &restoreSpecialCharacters( $session->{data} );
}

sub replaceSpecialCharacters {
    my $data = shift;

    foreach my $key ( keys %$data ) {
        if ( $key =~ /(\.|\$)/ ) {
            my $oldkey = $key;
            $key =~ s:\$:\\u0024:g;
            $key =~ s:\.:\\u002e:g;
            $data->{$key} = $data->{$oldkey};
            delete $data->{$oldkey};
        }
        if ( ref( $data->{$key} ) eq 'HASH' ) {
            &replaceSpecialCharacters( $data->{$key} );
        }
    }
}

sub restoreSpecialCharacters {
    my $data = shift;

    foreach my $key ( keys %$data ) {
        if ( $key =~ /(\\u0024|\\u002e)/ ) {
            my $oldkey = $key;
            $key =~ s:\\u0024:\$:g;
            $key =~ s:\\u002e:.:g;
            $data->{$key} = $data->{$oldkey};
            delete $data->{$oldkey};
        }
        if ( ref( $data->{$key} ) eq 'HASH' ) {
            &restoreSpecialCharacters( $data->{$key} );
        }
    }
}

1;
__END__

=head1 NAME

Apache::Session::Serialize::MongoDB - Does nothing since MongoDB can store Perl
objects;

=head1 SYNOPSIS

 use Apache::Session::MongoDB;
 
 tie %hash, 'Apache::Session::MongoDB', $id, {};

=head1 DESCRIPTION

This module does nothing.

=head1 SEE ALSO

L<Apache::Session::MongoDB>

=head1 AUTHOR

Xavier Guimard, E<lt>x.guimard@free.frE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2015-2016 by Xavier Guimard, E<lt>x.guimard@free.frE<gt>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=cut