line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Store::Storable; |
2
|
|
|
|
|
|
|
$Bot::BasicBot::Pluggable::Store::Storable::VERSION = '1.20'; |
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
546
|
use Storable qw( nstore retrieve ); |
|
1
|
|
|
|
|
2287
|
|
|
1
|
|
|
|
|
52
|
|
6
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
3
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use base qw( Bot::BasicBot::Pluggable::Store ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
381
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
13
|
1
|
50
|
|
|
|
7
|
if ( !$self->{dir} ) { |
14
|
0
|
|
|
|
|
0
|
$self->{dir} = File::Spec->curdir(); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub save { |
19
|
3
|
|
|
3
|
1
|
3
|
my $self = shift; |
20
|
3
|
|
|
|
|
4
|
my $namespace = shift; |
21
|
3
|
50
|
|
|
|
8
|
my @modules = $namespace ? ($namespace) : keys( %{ $self->{store} } ); |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
6
|
for my $name (@modules) { |
24
|
3
|
|
|
|
|
38
|
my $filename = File::Spec->catfile( $self->{dir}, $name . ".storable" ); |
25
|
3
|
|
|
|
|
13
|
my ( $fh, $tempfile ) = tempfile( DIR => $self->{dir}, UNLINK => 0 ); |
26
|
3
|
50
|
|
|
|
748
|
nstore( $self->{store}{$name}, $tempfile ) |
27
|
|
|
|
|
|
|
or die "Cannot save to $tempfile\n"; |
28
|
3
|
50
|
|
|
|
484
|
rename $tempfile, $filename |
29
|
|
|
|
|
|
|
or die "Cannot create $filename: $!\n"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub load { |
34
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
35
|
1
|
|
|
|
|
94
|
for my $file ( glob File::Spec->catfile( $self->{dir}, '*.storable' ) ) { |
36
|
0
|
|
|
|
|
|
my (undef, undef, $name) = map {File::Spec->splitpath($_)} $file =~ /^(.*?)\.storable$/; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->{store}{$name} = retrieve($file); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Store::Storable - use Storable to provide a storage backend |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 VERSION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
version 1.20 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $store = Bot::BasicBot::Pluggable::Store::Storable->new( |
56
|
|
|
|
|
|
|
dir => "directory" |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$store->set( "namespace", "key", "value" ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This is a L<Bot::BasicBot::Pluggable::Store> that uses Storable to store |
64
|
|
|
|
|
|
|
the values set by modules. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Mario Domgoergen <mdom@cpan.org> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
71
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |