line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Memcached::Fast::Logger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23133
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
534
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.15; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub store_namespace (&$); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
0
|
|
my ( $class, %opts ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
0
|
|
|
|
$opts{namespace} ||= 'logger:'; |
14
|
0
|
|
|
|
|
|
bless \%opts, $class; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
\%opts; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub log { |
20
|
0
|
|
|
0
|
1
|
|
my ( $self, $log ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
store_namespace { |
23
|
0
|
|
|
0
|
|
|
my $new_counter; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
0
|
|
|
|
warn "Cannot increment counter - maybe the connect to memcached was loosed" |
26
|
|
|
|
|
|
|
if ( ! defined $self->{cache}->add( 'log_counter', "0" ) |
27
|
|
|
|
|
|
|
|| ! defined ( $new_counter = $self->{cache}->incr('log_counter') ) |
28
|
|
|
|
|
|
|
|| ! defined $self->{cache}->set( "log_" . $new_counter, $log ) ); |
29
|
0
|
|
|
|
|
|
} $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub read_all { |
33
|
0
|
|
|
0
|
1
|
|
my ( $self, $sub ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
store_namespace { |
36
|
0
|
|
|
0
|
|
|
my $start = 0; |
37
|
0
|
|
|
|
|
|
my $cache = $self->{cache}; |
38
|
0
|
|
|
|
|
|
my ( $log, $ret ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
TERMINATE: while (1) { |
41
|
0
|
|
|
|
|
|
my ($lc) = $cache->gets('log_counter'); |
42
|
0
|
0
|
|
|
|
|
last unless defined $lc; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
for ( my $i = $start; $i <= $lc->[1]; $i++ ) { |
45
|
0
|
0
|
0
|
|
|
|
$sub->($log) && ( $cache->delete("log_$i"), 1 ) || last TERMINATE |
|
|
|
0
|
|
|
|
|
46
|
|
|
|
|
|
|
if ( defined( $log = $cache->get("log_$i") ) ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$ret = $cache->cas( 'log_counter', $lc->[0], "0" ); |
50
|
0
|
0
|
0
|
|
|
|
last if ! defined($ret) || $ret; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# If we are here so some other process has modified a log queue |
53
|
|
|
|
|
|
|
# We try reparse queue again |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$start = $lc->[1] + 1; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
} $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub store_namespace (&$) { |
61
|
0
|
|
|
0
|
0
|
|
my ( $code, $self ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $old_namespace = $self->{cache}->namespace( $self->{namespace} ); |
64
|
0
|
|
|
|
|
|
my $ret = eval { $code->() }; |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $error = $@; |
67
|
0
|
|
|
|
|
|
$self->{cache}->namespace( $old_namespace ); |
68
|
0
|
0
|
|
|
|
|
die if $@; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$ret; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |