line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MultiModule::Tasks::FollowTail; |
2
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::VERSION = '1.141220'; |
3
|
1
|
|
|
1
|
|
786
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
45
|
|
6
|
1
|
|
|
1
|
|
1095
|
use Data::Dumper; |
|
1
|
|
|
|
|
8738
|
|
|
1
|
|
|
|
|
115
|
|
7
|
1
|
|
|
1
|
|
409
|
use POE qw(Wheel::FollowTail); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Message::Transform qw(mtransform); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use parent 'App::MultiModule::Task'; |
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
App::MultiModule::Tasks::FollowTail - File following task for App::MultiModule |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 message |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub message { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
my $message = shift; |
24
|
|
|
|
|
|
|
my %args = @_; |
25
|
|
|
|
|
|
|
$self->debug('message', message => $message) |
26
|
|
|
|
|
|
|
if $self->{debug} > 5; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _got_log_line { |
30
|
|
|
|
|
|
|
my ($logfile, $line) = @_; |
31
|
|
|
|
|
|
|
my @follow_names = keys %{$App::MultiModule::Tasks::FollowTail::logfile_map->{$logfile}}; |
32
|
|
|
|
|
|
|
foreach my $follow_name (@follow_names) { |
33
|
|
|
|
|
|
|
my $follow_info = $App::MultiModule::Tasks::FollowTail::config->{follows}->{$follow_name}; |
34
|
|
|
|
|
|
|
my $regex_string = $follow_info->{regex}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if(not $App::MultiModule::Tasks::FollowTail::regex_cache->{$regex_string}) { |
37
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::regex_cache->{$regex_string} = qr/$regex_string/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
my $re = $App::MultiModule::Tasks::FollowTail::regex_cache->{$regex_string}; |
40
|
|
|
|
|
|
|
if($line =~ $re) { |
41
|
|
|
|
|
|
|
my $message = { |
42
|
|
|
|
|
|
|
line => $line, |
43
|
|
|
|
|
|
|
logfile => $logfile, |
44
|
|
|
|
|
|
|
follow_name => $follow_name, |
45
|
|
|
|
|
|
|
regex_string => $regex_string, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
if(%+) { |
48
|
|
|
|
|
|
|
while(my($key, $value) = each %+) { |
49
|
|
|
|
|
|
|
$message->{$key} = $value; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
mtransform $message, $follow_info->{transform} |
53
|
|
|
|
|
|
|
if $follow_info->{transform}; |
54
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::self->emit($message); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 set_config |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
sub set_config { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
my $config = shift; |
65
|
|
|
|
|
|
|
$self->{config} = $config; |
66
|
|
|
|
|
|
|
#perhaps premature optimization, but this thing has to be *fast* |
67
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::config = $config; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if(not $self->{local_state}) { |
70
|
|
|
|
|
|
|
$self->{local_state} = { |
71
|
|
|
|
|
|
|
following_files => {}, |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::regex_cache = {}; |
74
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::logfile_map = {}; |
75
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::self = $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
my $state = $self->{local_state}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if($config->{follows}) { |
80
|
|
|
|
|
|
|
my @follow_names = sort keys %{$config->{follows}}; |
81
|
|
|
|
|
|
|
foreach my $follow_name (@follow_names) { |
82
|
|
|
|
|
|
|
my $follow_info = $config->{follows}->{$follow_name}; |
83
|
|
|
|
|
|
|
next unless my $logfile = $follow_info->{logfile}; |
84
|
|
|
|
|
|
|
$App::MultiModule::Tasks::FollowTail::logfile_map->{$logfile}->{$follow_name} = 1; |
85
|
|
|
|
|
|
|
next if $state->{following_files}->{$logfile}; |
86
|
|
|
|
|
|
|
$self->add_session( |
87
|
|
|
|
|
|
|
{ inline_states => { |
88
|
|
|
|
|
|
|
_start => sub { |
89
|
|
|
|
|
|
|
$_[HEAP]{tailor} = POE::Wheel::FollowTail->new( |
90
|
|
|
|
|
|
|
Filename => $logfile, |
91
|
|
|
|
|
|
|
InputEvent => 'got_log_line', |
92
|
|
|
|
|
|
|
ResetEvent => 'got_log_rollover', |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
got_log_line => sub { |
96
|
|
|
|
|
|
|
_got_log_line($logfile, $_[ARG0]); |
97
|
|
|
|
|
|
|
}, |
98
|
|
|
|
|
|
|
got_log_rollover => sub { |
99
|
|
|
|
|
|
|
}, |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
$state->{following_files}->{$logfile} = 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
$self->debug('Router: set_config') if $self->{debug}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Dana M. Diederich, C<< <dana@realms.org> >> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 BUGS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Please report any bugs or feature requests through L<https://github.com/dana/App-MultiModule-Tasks-FollowTail/issues>. I will be notified, and then you'll |
116
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SUPPORT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
perldoc App::MultiModule::Tasks::FollowTail |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
You can also look for information at: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * Report bugs here: |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<https://github.com/dana/App-MultiModule-Tasks-FollowTail/issues> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L<http://annocpan.org/dist/App-MultiModule-Tasks-FollowTail> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * CPAN Ratings |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/App-MultiModule-Tasks-FollowTail> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * Search CPAN |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L<https://metacpan.org/module/App::MultiModule::Tasks::FollowTail> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright 2014 Dana M. Diederich. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
154
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
155
|
|
|
|
|
|
|
copy of the full license at: |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
160
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
161
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
162
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
165
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
166
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
169
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
172
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
173
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
174
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
175
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
176
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
177
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
178
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
181
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
182
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
183
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
184
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
185
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
186
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
187
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; # End of App::MultiModule::Tasks::FollowTail |