line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JLogger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
655
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
31
|
use 5.008_001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001'; |
7
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Carp; |
10
|
1
|
|
|
1
|
|
836
|
use Class::Load 'load_class'; |
|
1
|
|
|
|
|
85390
|
|
|
1
|
|
|
|
|
95
|
|
11
|
1
|
|
|
1
|
|
12
|
use Scalar::Util 'weaken'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
971
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
0
|
1163
|
my ($class, %args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
9
|
if (my $transport_data = delete $args{transport}) { |
19
|
0
|
|
|
|
|
0
|
$self->transport($transport_data); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
50
|
|
|
11
|
$self->handlers(delete $args{handlers} |
23
|
|
|
|
|
|
|
|| {message => ['JLogger::Handler::Message']}); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
50
|
|
|
11
|
$self->filters(delete $args{filters} || []); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
50
|
|
|
8
|
$self->storages(delete $args{storages} || []); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->{on_disconnect} = |
31
|
1
|
50
|
|
0
|
|
9
|
exists $args{on_disconnect} ? $args{on_disconnect} : sub { }; |
|
0
|
|
|
|
|
0
|
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
6
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub transport { |
37
|
0
|
|
|
0
|
0
|
0
|
my ($self, $transport_data) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
0
|
return $self->{transport} unless defined $transport_data; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
weaken $self; |
42
|
|
|
|
|
|
|
$self->{transport} = $self->build_element( |
43
|
|
|
|
|
|
|
$transport_data, |
44
|
0
|
|
|
0
|
|
0
|
on_message => sub { $self->_on_message($_[1]) }, |
45
|
0
|
|
|
0
|
|
0
|
on_disconnect => sub { $self->on_disconnect->($self) }, |
46
|
0
|
|
|
|
|
0
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub handlers { |
50
|
1
|
|
|
1
|
0
|
3
|
my ($self, $handlers) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
7
|
return $self->{handlers} unless defined $handlers; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
8
|
$self->{handlers} = {}; |
55
|
1
|
|
|
|
|
6
|
while (my ($handler_name, $handler_data) = each %$handlers) { |
56
|
1
|
|
|
|
|
3
|
$self->{handlers}->{$handler_name} = |
57
|
|
|
|
|
|
|
$self->build_element($handler_data); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub filters { |
62
|
1
|
|
|
1
|
0
|
3
|
my ($self, $filters) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
3
|
return $self->{filters} unless defined $filters; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
$self->{filters} = []; |
67
|
1
|
|
|
|
|
4
|
foreach my $filter (@$filters) { |
68
|
0
|
|
|
|
|
0
|
push @{$self->{filters}}, $self->build_element($filter); |
|
0
|
|
|
|
|
0
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub storages { |
73
|
1
|
|
|
1
|
0
|
22
|
my ($self, $storages) = @_; |
74
|
|
|
|
|
|
|
|
75
|
1
|
50
|
|
|
|
4
|
return $self->{storages} unless defined $storages; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
3
|
$self->{storages} = []; |
78
|
1
|
|
|
|
|
3
|
foreach my $store (@$storages) { |
79
|
0
|
|
|
|
|
0
|
push @{$self->{storages}}, $self->build_element($store); |
|
0
|
|
|
|
|
0
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub on_disconnect { |
84
|
0
|
0
|
|
0
|
0
|
0
|
@_ > 1 ? $_[0]->{on_disconnect} = $_[1] : $_[0]->{on_disconnect}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub connect { |
88
|
0
|
|
|
0
|
0
|
0
|
$_[0]->transport->connect; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub disconnect { |
92
|
0
|
|
|
0
|
0
|
0
|
$_[0]->transport->disconnect; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub build_element { |
96
|
1
|
|
|
1
|
0
|
3
|
my ($self, $element, %extra_args) = @_; |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
2
|
my ($element_class, $args) = @$element; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
50
|
|
|
6
|
$args ||= {}; |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
4
|
load_class $element_class; |
103
|
1
|
|
|
|
|
41
|
$element_class->new(%$args, %extra_args); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _on_message { |
107
|
0
|
|
|
0
|
|
|
my ($self, $node) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach my $node ($node->nodes) { |
110
|
0
|
0
|
|
|
|
|
if (my $handler = $self->{handlers}->{$node->name}) { |
111
|
0
|
0
|
|
|
|
|
if (my $data = $handler->handle($node)) { |
112
|
0
|
0
|
|
|
|
|
unless ($self->_check_filters($data)) { |
113
|
0
|
|
|
|
|
|
$self->_store_result($data); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _check_filters { |
121
|
0
|
|
|
0
|
|
|
my ($self, $data) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
foreach my $filter (@{$self->filters}) { |
|
0
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
return 1 if $filter->filter($data); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
0; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _store_result { |
131
|
0
|
|
|
0
|
|
|
my ($self, $data) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
foreach my $store (@{$self->storages}) { |
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$store->store($data); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
__END__ |