RemoteTail/Engine/Default.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 CC 4 SCAR 24.0
CC
4
Cov
0%
process_entry
20.0
new
2.0
BEGIN
2.0
CRAP 11.0
1 package POE::Component::RemoteTail::Engine::Default;
2  
3 use strict;
4 use warnings;
5 use POE::Component::IKC::ClientLite;
6  
7 sub new {
8 my $class = shift;
9 my %args = @_;
10  
11 return bless {%args}, $class;
12 }
13  
14 sub process_entry {
15 my $class = shift;
16 my $arg = shift;
17  
18 my $client_name = "Client$$";
19 my $remote = create_ikc_client(
20 port => $arg->{port},
21 name => $client_name,
22 timeout => 5
23 );
24 die $POE::Component::IKC::ClientLite::error unless $remote;
25  
26 my $host = $arg->{host};
27 my $path = $arg->{path};
28 my $user = $arg->{user};
29 my $password = $arg->{password};
30 my $tail = "tail -f $path";
31  
32 my $fh;
33 my $pre = 0;
34 my $logs;
35 my $cmd = "ssh -A $host $tail";
36  
37 local $SIG{'INT'} = $SIG{'HUP'} = $SIG{'QUIT'} = $SIG{'TERM'} = sub {
38 my $killcmd = 'pkill -f "' . $cmd . '"';
39 system($killcmd);
40 close($fh);
41 };
42  
43 open( $fh, "$cmd |" );
44 while (<$fh>) {
45 my $now = time;
46 unless ( $now == $pre ) {
47 my $ret =
48 $remote->post_respond( 'tailer/_ikc_logger', [ $host, $logs ] );
49 unless ($ret) {
50 close($fh);
51 exit;
52 }
53 $pre = $now;
54 $logs = "";
55 }
56 else {
57 $logs .= $_;
58 }
59 }
60 close($fh);
61 }
62  
63 1;
64  
65 __END__