line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Tail::Multi; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
153790
|
use 5.006001; |
|
8
|
|
|
|
|
33
|
|
|
8
|
|
|
|
|
478
|
|
4
|
8
|
|
|
8
|
|
47
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
273
|
|
5
|
8
|
|
|
8
|
|
62
|
use warnings; |
|
8
|
|
|
|
|
117
|
|
|
8
|
|
|
|
|
727
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
9489
|
use File::Tail; |
|
8
|
|
|
|
|
314665
|
|
|
8
|
|
|
|
|
502
|
|
10
|
8
|
|
|
8
|
|
2785
|
use Test::Builder; |
|
8
|
|
|
|
|
23579
|
|
|
8
|
|
|
|
|
184
|
|
11
|
8
|
|
|
8
|
|
51
|
use Carp; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
1094
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
14
|
|
|
|
|
|
|
our @monitored; |
15
|
|
|
|
|
|
|
our $cached_output; |
16
|
|
|
|
|
|
|
our $tail_delay = 5; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
8
|
|
|
8
|
|
71
|
my $self = shift; |
20
|
8
|
|
|
|
|
23
|
my $caller = caller; |
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
93
|
no strict 'refs'; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
785
|
|
23
|
8
|
|
|
|
|
17
|
*{$caller."::delay"} = \&delay; |
|
8
|
|
|
|
|
110
|
|
24
|
8
|
|
|
|
|
17
|
*{$caller."::add_file"} = \&add_file; |
|
8
|
|
|
|
|
218
|
|
25
|
8
|
|
|
|
|
19
|
*{$caller."::contents_like"} = \&contents_like; |
|
8
|
|
|
|
|
31
|
|
26
|
8
|
|
|
|
|
17
|
*{$caller."::contents_unlike"} = \&contents_unlike; |
|
8
|
|
|
|
|
36
|
|
27
|
|
|
|
|
|
|
|
28
|
8
|
|
|
|
|
16
|
my %params; |
29
|
|
|
|
|
|
|
{ |
30
|
8
|
|
|
8
|
|
45
|
no warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
5656
|
|
|
8
|
|
|
|
|
12
|
|
31
|
8
|
|
|
|
|
26
|
%params = @_; |
32
|
|
|
|
|
|
|
} |
33
|
8
|
100
|
|
|
|
40
|
if (exists($params{'files'})) { |
34
|
4
|
|
|
|
|
9
|
my $contents = $params{'files'}; |
35
|
4
|
100
|
33
|
|
|
25
|
if (ref($contents) eq 'ARRAY') { |
|
|
50
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# list of files provided |
37
|
2
|
|
|
|
|
5
|
@monitored = map {File::Tail->new(name=>$_)} @$contents; |
|
2
|
|
|
|
|
994
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif (defined $contents and ($contents ne "")) { |
40
|
2
|
|
|
|
|
18
|
@monitored = File::Tail->new(name=>$contents); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
0
|
croak "You must specify at least one file to monitor"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
8
|
|
|
|
|
1312
|
delete $params{'files'}; |
47
|
|
|
|
|
|
|
|
48
|
8
|
100
|
|
|
|
15698
|
$Test->plan(%params) if int keys %params; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub delay($;$) { |
52
|
3
|
|
|
3
|
0
|
1652
|
my ($delay, $comment) = @_; |
53
|
3
|
50
|
|
|
|
15
|
$tail_delay = $delay if defined $delay; |
54
|
3
|
100
|
|
|
|
16
|
$Test->diag($comment) if defined $comment; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_file($;$) { |
59
|
4
|
|
|
4
|
0
|
1194
|
my($file, $comment) = @_; |
60
|
4
|
|
|
|
|
30
|
push @monitored, File::Tail->new($file); |
61
|
3
|
100
|
|
|
|
1322
|
$Test->diag($comment) if defined $comment; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub contents_like(&$;$) { |
65
|
2
|
|
|
2
|
0
|
1070
|
my ($coderef, $pattern, $comment) = @_; |
66
|
2
|
|
|
2
|
|
12
|
_execute($coderef, $pattern, sub { $Test->like(@_) }, $comment); |
|
2
|
|
|
|
|
23
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub contents_unlike(&$;$) { |
70
|
2
|
|
|
2
|
0
|
1343
|
my ($coderef, $pattern, $comment) = @_; |
71
|
2
|
|
|
2
|
|
24
|
_execute($coderef, $pattern, sub { $Test->unlike(@_) }, $comment); |
|
2
|
|
|
|
|
39
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _execute { |
75
|
4
|
|
|
4
|
|
10
|
my ($coderef, $pattern, $testsub, $comment) = @_; |
76
|
4
|
100
|
|
|
|
14
|
if (defined $coderef) { |
77
|
|
|
|
|
|
|
# call code and capture output |
78
|
2
|
|
|
|
|
7
|
$coderef->(); |
79
|
2
|
|
|
|
|
8624
|
my ($nfound, $timeleft, @pending); |
80
|
2
|
|
|
|
|
81
|
$nfound = 1; |
81
|
2
|
|
|
|
|
29
|
while ($nfound) { |
82
|
3
|
|
|
|
|
470
|
($nfound, $timeleft, @pending) = |
83
|
|
|
|
|
|
|
File::Tail::select(undef, undef, undef, $tail_delay, @monitored); |
84
|
3
|
100
|
|
|
|
4620655
|
last unless ($nfound); |
85
|
1
|
|
|
|
|
7
|
foreach (@pending) { |
86
|
1
|
|
|
|
|
229
|
$cached_output .= $_->{"input"}." (".localtime(time).") ".$_->read; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
# test vs. last output |
91
|
|
|
|
|
|
|
# (fall into here if coderef is not defined) |
92
|
4
|
|
|
|
|
23
|
$testsub->($cached_output, $pattern, $comment); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |