File: berkeleydb.pl

package info (click to toggle)
libdata-session-perl 1.18-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 2,916; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 1,121 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
#!/usr/bin/env perl

use strict;
use warnings;

use BerkeleyDB;

use Data::Session;

use File::Spec;
use File::Temp;

# -------------------

# The EXLOCK is for BSD-based systems.

my($file_name) = File::Temp -> new(EXLOCK => 0, SUFFIX => '.bdb');
my($env)       = BerkeleyDB::Env -> new
(
	Home => File::Spec -> tmpdir,
	Flags => DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL,
);
if (! $env)
{
	print "BerkeleyDB is not responding. \n";
	exit;
}
my($bdb) = BerkeleyDB::Hash -> new(Env => $env, Filename => $file_name, Flags => DB_CREATE);
if (! $bdb)
{
	print "BerkeleyDB is not responding. \n";
	exit;
}
my($type) = 'driver:BerkeleyDB;id:SHA1;serialize:DataDumper'; # Case-sensitive.

my($id);

{
my($session) = Data::Session -> new
(
	cache => $bdb,
	type  => $type,
) || die $Data::Session::errstr;

$id = $session -> id;

$session -> param(a_key => 'a_value');

print "Id: $id. Save a_key: a_value. \n";
}

{
my($session) = Data::Session -> new
(
	cache => $bdb,
	id    => $id,
	type  => $type,
) || die $Data::Session::errstr;

print "Id: $id. Recover a_key: ", $session -> param('a_key'), ". \n";

$session -> delete;
}