| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Tail::Lite; |
|
2
|
2
|
|
|
2
|
|
36577
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
72
|
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
800
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
|
8
|
1
|
|
|
1
|
1
|
11
|
my $pkg = shift; |
|
9
|
1
|
|
|
|
|
6
|
my $self = {@_}; |
|
10
|
1
|
|
|
|
|
2
|
bless $self, $pkg; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
50
|
33
|
|
|
25
|
unless ( defined $self->{filename} and -e $self->{filename} ) { |
|
13
|
0
|
|
|
|
|
0
|
$self->{error} = 1; |
|
14
|
0
|
|
|
|
|
0
|
$self->{errinfo} = "error input filename"; |
|
15
|
0
|
|
|
|
|
0
|
return $self; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
37
|
unless ( open $self->{fh}, "<", $self->{filename} ) { |
|
19
|
0
|
|
|
|
|
0
|
$self->{error} = 1; |
|
20
|
0
|
|
|
|
|
0
|
$self->{errinfo} = "error open file"; |
|
21
|
0
|
|
|
|
|
0
|
return $self; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
2
|
my $seek_position; |
|
25
|
|
|
|
|
|
|
my $seek_whence; # 0:begin, 1:current, 2:eof |
|
26
|
1
|
50
|
|
|
|
6
|
if ( !defined $self->{seekpos} ) { |
|
27
|
0
|
|
|
|
|
0
|
$seek_position = 0; |
|
28
|
0
|
|
|
|
|
0
|
$seek_whence = 2; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
else { |
|
31
|
1
|
50
|
33
|
|
|
14
|
if ( $self->{seekpos} eq 'begin' |
|
|
|
0
|
33
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
32
|
|
|
|
|
|
|
or $self->{seekpos} eq 'new' |
|
33
|
|
|
|
|
|
|
or $self->{seekpos} eq 'start' ) |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
1
|
|
|
|
|
2
|
$seek_position = 0; |
|
36
|
1
|
|
|
|
|
2
|
$seek_whence = 0; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
elsif ( $self->{seekpos} eq 'end' or $self->{seekpos} eq 'eof' ) { |
|
39
|
0
|
|
|
|
|
0
|
$seek_position = 0; |
|
40
|
0
|
|
|
|
|
0
|
$seek_whence = 2; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif ( $self->{seekpos} !~ /^[0-9]+$/ ) { |
|
43
|
0
|
|
|
|
|
0
|
$seek_position = $self->{seekpos}; |
|
44
|
0
|
|
|
|
|
0
|
$seek_whence = 0; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
0
|
|
|
|
|
0
|
$self->{error} = 1; |
|
48
|
0
|
|
|
|
|
0
|
$self->{errinfo} = "error seekpos"; |
|
49
|
0
|
|
|
|
|
0
|
return $self; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
1
|
50
|
|
|
|
9
|
unless ( sysseek( $self->{fh}, $seek_position, $seek_whence ) ) { |
|
53
|
0
|
|
|
|
|
0
|
$self->{error} = 1; |
|
54
|
0
|
|
|
|
|
0
|
$self->{errinfo} = "error seek file"; |
|
55
|
0
|
|
|
|
|
0
|
return $self; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
0
|
33
|
|
|
9
|
$self->{maxbuf} = 1024 |
|
|
|
|
33
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if !$self->{maxbuf} |
|
60
|
|
|
|
|
|
|
or int( $self->{maxbuf} ) < 1 |
|
61
|
|
|
|
|
|
|
or int( $self->{maxbuf} ) > 1024 * 1024; |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
5
|
return $self; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub readline { |
|
67
|
18
|
|
|
18
|
1
|
81
|
my $self = shift; |
|
68
|
18
|
50
|
|
|
|
38
|
if ( $self->{error} ) { |
|
69
|
0
|
|
|
|
|
0
|
return $self->{errinfo}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
18
|
|
|
|
|
15
|
my $line; |
|
73
|
18
|
|
|
|
|
22
|
while (1) { |
|
74
|
4492
|
|
|
|
|
2898
|
my $buf; |
|
75
|
4492
|
|
|
|
|
9407
|
my $ret = sysread( $self->{fh}, $buf, 1 ); |
|
76
|
4492
|
50
|
|
|
|
4954
|
if ($ret) { |
|
77
|
4492
|
|
|
|
|
3371
|
$line .= $buf; |
|
78
|
4492
|
100
|
66
|
|
|
15830
|
if ( $buf =~ /[\r\n]/ or length($line) >= $self->{maxbuf} ) { |
|
79
|
18
|
|
|
|
|
150
|
return ( sysseek( $self->{fh}, 0, 1 ), $line ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
else { |
|
83
|
0
|
|
|
|
|
|
sleep 1; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |