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