line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::LogFile; |
2
|
3
|
|
|
3
|
|
129020
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
132
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
107
|
|
4
|
3
|
|
|
3
|
|
17
|
use base qw(Exporter); |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
372
|
|
5
|
3
|
|
|
3
|
|
4285
|
use File::Temp qw(tempfile); |
|
3
|
|
|
|
|
113894
|
|
|
3
|
|
|
|
|
325
|
|
6
|
3
|
|
|
3
|
|
26
|
use Test::More; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
our @EXPORT = qw/ |
10
|
|
|
|
|
|
|
log_file |
11
|
|
|
|
|
|
|
count_ok |
12
|
|
|
|
|
|
|
/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub log_file { |
15
|
3
|
|
|
3
|
1
|
6431
|
my ( $fh, $filename ) = tempfile; |
16
|
3
|
100
|
|
|
|
1967
|
return wantarray ? ( $fh, $filename ) : $filename; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub count_ok { |
20
|
1
|
|
|
1
|
1
|
204
|
my %args = @_; |
21
|
1
|
50
|
|
|
|
6
|
my $log_file = $args{file} or die "arg file is not found"; |
22
|
1
|
50
|
|
|
|
5
|
my $str = $args{str} or die "arg str is not found"; |
23
|
1
|
50
|
|
|
|
8
|
my $count = $args{count} or die "arg count is not found"; |
24
|
1
|
|
50
|
|
|
5
|
my $msg = $args{msg} || "log count is valid"; |
25
|
1
|
|
|
|
|
3
|
my $hook = $args{hook}; |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
47
|
open my $fh, '<', $log_file or die $!; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
3
|
my $find = 0; |
30
|
1
|
|
|
|
|
25
|
while (<$fh>) { |
31
|
2
|
|
|
|
|
1126
|
my $line = $_; |
32
|
2
|
50
|
|
|
|
21
|
if ( $line =~ /$str/ ) { |
33
|
2
|
|
|
|
|
4
|
$find++; |
34
|
2
|
50
|
33
|
|
|
16
|
if ( $hook && ( ref $hook eq 'CODE' ) ) { |
35
|
2
|
|
|
|
|
6
|
$hook->($line); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
605
|
is( $find, $count, $msg ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
__END__ |