line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Store::Storable; |
2
|
|
|
|
|
|
|
$Bot::BasicBot::Pluggable::Store::Storable::VERSION = '1.10'; |
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
584
|
use Storable qw( nstore retrieve ); |
|
1
|
|
|
|
|
2398
|
|
|
1
|
|
|
|
|
90
|
|
6
|
1
|
|
|
1
|
|
7
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
8
|
use base qw( Bot::BasicBot::Pluggable::Store ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
466
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
13
|
1
|
50
|
|
|
|
6
|
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
|
|
|
|
|
2
|
my $namespace = shift; |
21
|
3
|
50
|
|
|
|
7
|
my @modules = $namespace ? ($namespace) : keys( %{ $self->{store} } ); |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
4
|
for my $name (@modules) { |
24
|
3
|
|
|
|
|
25
|
my $filename = File::Spec->catfile( $self->{dir}, $name . ".storable" ); |
25
|
3
|
|
|
|
|
11
|
my ( $fh, $tempfile ) = tempfile( DIR => $self->{dir}, UNLINK => 0 ); |
26
|
3
|
50
|
|
|
|
684
|
nstore( $self->{store}{$name}, $tempfile ) |
27
|
|
|
|
|
|
|
or die "Cannot save to $tempfile\n"; |
28
|
3
|
50
|
|
|
|
494
|
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
|
|
|
|
|
103
|
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.10 |
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. |