| 1 | package File::Tail; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $Is_Win32); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | $Is_Win32 = ($^O =~ /win32/i) ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 3 | require Exporter; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 3 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||
| 13 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||
| 14 | 3 | $VERSION = '1.2'; | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | # Preloaded methods go here. | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | #use IO::Seekable; # does not define SEEK_SET in 5005.02 | ||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use File::stat; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Time::HiRes qw ( time sleep ); #import hires microsecond timers | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | sub SEEK_SET () {0;} | ||||||||||||||||||||||||||||||||
| 26 | sub SEEK_CUR () {1;} | ||||||||||||||||||||||||||||||||
| 27 | sub SEEK_END () {2;} | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | sub interval { | ||||||||||||||||||||||||||||||||
| 31 | 116 | ▶ | my $object=shift @_; | ||||||||||||||||||||||||||||||
|
Subroutine
interval: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 32 | 116 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 18 | $object->{interval}=shift; | |||||||||||||||||||||||||||||||
| 34 | $object->{interval}=$object->{maxinterval} if | ||||||||||||||||||||||||||||||||
| 35 | 18 | ▶ | $object->{interval}>$object->{maxinterval}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | 116 | $object->{interval}; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | sub logit { | ||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $object=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
logit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 42 | 0 | my @call=caller(1); | |||||||||||||||||||||||||||||||
| 43 | print # STDERR | ||||||||||||||||||||||||||||||||
| 44 | # time()." ". | ||||||||||||||||||||||||||||||||
| 45 | "\033[7m". | ||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $call[3]." ".$object->{"input"}." ".join("",@_). | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | "\033[0m". | ||||||||||||||||||||||||||||||||
| 48 | "\n" | ||||||||||||||||||||||||||||||||
| 49 | if $object->debug; | ||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | sub adjustafter { | ||||||||||||||||||||||||||||||||
| 53 | 42 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
adjustafter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | 42 | ▶ | $self->{adjustafter}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 42 | return $self->{adjustafter}; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | sub debug { | ||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->{"debug"}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 0 | return $self->{"debug"}; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | sub errmode { | ||||||||||||||||||||||||||||||||
| 65 | 9 | ▶ | my($self, $mode) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
errmode: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 66 | 9 | my($prev) = $self->{errormode}; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 9 | ▶ | if (@_ >= 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | ## Set the error mode. | ||||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | defined $mode or $mode = ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 9 | ▶ | if (ref($mode) eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 72 | 0 | $self->{errormode} = $mode; | |||||||||||||||||||||||||||||||
| 73 | } elsif (ref($mode) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | unless (ref($mode->[0]) eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 0 | croak 'bad errmode: first item in list must be a code ref'; | |||||||||||||||||||||||||||||||
| 76 | 0 | $mode = 'die'; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{errormode} = $mode; | |||||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||||||
| 80 | 9 | $self->{errormode} = lc $mode; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | 9 | $prev; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | sub errmsg { | ||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my($self, @errmsgs) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
errmsg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 88 | 0 | my($prev) = $self->{errormsg}; | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (@_ > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | 0 | $self->{errormsg} = join '', @errmsgs; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 0 | $prev; | |||||||||||||||||||||||||||||||
| 95 | } # end sub errmsg | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | sub error { | ||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my($self, @errmsg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 100 | my( | ||||||||||||||||||||||||||||||||
| 101 | 0 | $errmsg, | |||||||||||||||||||||||||||||||
| 102 | $func, | ||||||||||||||||||||||||||||||||
| 103 | $mode, | ||||||||||||||||||||||||||||||||
| 104 | @args, | ||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if (@_ >= 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | ## Put error message in the object. | ||||||||||||||||||||||||||||||||
| 109 | 0 | $errmsg = join '', @errmsg; | |||||||||||||||||||||||||||||||
| 110 | 0 | $self->{"errormsg"} = $errmsg; | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | ## Do the error action as described by error mode. | ||||||||||||||||||||||||||||||||
| 113 | 0 | $mode = $self->{"errormode"}; | |||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (ref($mode) eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 115 | 0 | &$mode($errmsg); | |||||||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||||||
| 117 | } elsif (ref($mode) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
| 118 | 0 | ($func, @args) = @$mode; | |||||||||||||||||||||||||||||||
| 119 | 0 | &$func(@args); | |||||||||||||||||||||||||||||||
| 120 | 0 | return; | |||||||||||||||||||||||||||||||
| 121 | } elsif ($mode eq "return") { | ||||||||||||||||||||||||||||||||
| 122 | 0 | return; | |||||||||||||||||||||||||||||||
| 123 | } elsif ($mode eq "warn") { | ||||||||||||||||||||||||||||||||
| 124 | 0 | carp $errmsg; | |||||||||||||||||||||||||||||||
| 125 | } else { # die | ||||||||||||||||||||||||||||||||
| 126 | 0 | croak $errmsg; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||
| 129 | 0 | return $self->{"errormsg"} ne ''; | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | } # end sub error | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | sub copy { | ||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 136 | 9 | ▶ | $self->{copy}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 9 | return $self->{copy}; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | sub tail { | ||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
tail: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $self->{"tail"}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 0 | return $self->{"tail"}; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | sub reset_tail { | ||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
reset_tail: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $self->{reset_tail}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 149 | 0 | return $self->{reset_tail}; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | sub nowait { | ||||||||||||||||||||||||||||||||
| 153 | 24 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
nowait: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | $self->{nowait}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 24 | return $self->{nowait}; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | sub method { | ||||||||||||||||||||||||||||||||
| 159 | 9 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
method: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 160 | 9 | ▶ | $self->{method}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | 9 | return $self->{method}; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | sub input { | ||||||||||||||||||||||||||||||||
| 165 | 19 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
input: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 166 | 19 | ▶ | $self->{input}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | 19 | return $self->{input}; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | sub maxinterval { | ||||||||||||||||||||||||||||||||
| 171 | 18 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
maxinterval: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 172 | 18 | ▶ | $self->{maxinterval}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 173 | 18 | return $self->{maxinterval}; | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | sub resetafter { | ||||||||||||||||||||||||||||||||
| 177 | 9 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
resetafter: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | $self->{resetafter}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 179 | 9 | return $self->{resetafter}; | |||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | sub ignore_nonexistant { | ||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
ignore_nonexistant: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $self->{ignore_nonexistant}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 185 | 0 | return $self->{ignore_nonexistant}; | |||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | sub name_changes { | ||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
name_changes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $self->{name_changes_callback}=shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | 0 | return $self->{name_changes_callback}; | |||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | sub TIEHANDLE { | ||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $ref=new(@_); | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | sub READLINE { | ||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $_[0]->read(); | ||||||||||||||||||||||||||||||
|
Subroutine
READLINE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | sub PRINT { | ||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $_[0]->error("PRINT makes no sense in File::Tail"); | ||||||||||||||||||||||||||||||
|
Subroutine
PRINT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | sub PRINTF { | ||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $_[0]->error("PRINTF makes no sense in File::Tail"); | ||||||||||||||||||||||||||||||
|
Subroutine
PRINTF: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | sub READ { | ||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $_[0]->error("READ not implemented in File::Tail -- use READLINE (<HANDLE>) instead"); | ||||||||||||||||||||||||||||||
|
Subroutine
READ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | sub GETC { | ||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $_[0]->error("GETC not (yet) implemented in File::Tail -- use READLINE (<HANDLE>) instead"); | ||||||||||||||||||||||||||||||
|
Subroutine
GETC: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | sub DESTROY { | ||||||||||||||||||||||||||||||||
| 219 | 14 | ▶ | my($this) = $_[0]; | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||
| 220 | 14 | ▶ | close($this->{"handle"}) if (defined($this) && defined($this->{'handle'})); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $this and defined $this->{"handle"}
MC/DC0%0/2
defined $this and defined $this->{"handle"}
defined $this
defined $this->{"handle"}
Truth table33%1/3
A and B
A= defined $thisB= defined $this->{"handle"}
| |||||||||||||||||||||||||||||||||
| 221 | # undef $_[0]; | ||||||||||||||||||||||||||||||||
| 222 | 14 | return; | |||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | sub CLOSE { | ||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | &DESTROY(@_); | ||||||||||||||||||||||||||||||
|
Subroutine
CLOSE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | sub new { | ||||||||||||||||||||||||||||||||
| 230 | 9 | ▶ | my ($pkg)=shift @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=20 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 231 | 9 | ▶ | $pkg=ref($pkg) || $pkg; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||||||
| 232 | 9 | ▶ | unless ($pkg) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 233 | 0 | $pkg="File::Tail"; | |||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||
| 235 | 9 | my %params; | |||||||||||||||||||||||||||||||
| 236 | 9 | ▶ | if ($#_ == 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | 0 | $params{"name"}=$_[0]; | |||||||||||||||||||||||||||||||
| 238 | } else { | ||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | if (($#_ % 2) != 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | 0 | croak "Odd number of parameters for new"; | |||||||||||||||||||||||||||||||
| 241 | 0 | return; | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | 9 | %params=@_; | |||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | 9 | my $object = {}; | |||||||||||||||||||||||||||||||
| 246 | 9 | bless $object,$pkg; | |||||||||||||||||||||||||||||||
| 247 | 9 | ▶ | unless (defined($params{'name'})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 248 | 0 | croak "No file name given. Pass filename as \"name\" parameter"; | |||||||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||
| 251 | 9 | $object->input($params{'name'}); | |||||||||||||||||||||||||||||||
| 252 | 9 | $object->copy($params{'cname'}); | |||||||||||||||||||||||||||||||
| 253 | 9 | ▶ | $object->method($params{'method'} || "tail"); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'method'} || 'tail'
MC/DC0%0/1
$params{'method'} || 'tail'
$params{'method'}
Truth table50%1/2
A
A= $params{'method'}
| |||||||||||||||||||||||||||||||||
| 254 | 9 | $object->{buffer}=""; | |||||||||||||||||||||||||||||||
| 255 | 9 | ▶ | $object->maxinterval($params{'maxinterval'} || 60); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'maxinterval'} || 60
MC/DC0%0/1
$params{'maxinterval'} || 60
$params{'maxinterval'}
Truth table50%1/2
A
A= $params{'maxinterval'}
| |||||||||||||||||||||||||||||||||
| 256 | 9 | ▶ | $object->interval($params{'interval'} || 10); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'interval'} || 10
MC/DC100%1/1
$params{'interval'} || 10
$params{'interval'}
Truth table100%2/2
A
A= $params{'interval'}
| |||||||||||||||||||||||||||||||||
| 257 | 9 | ▶ | $object->adjustafter($params{'adjustafter'} || 10); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'adjustafter'} || 10
MC/DC0%0/1
$params{'adjustafter'} || 10
$params{'adjustafter'}
Truth table50%1/2
A
A= $params{'adjustafter'}
| |||||||||||||||||||||||||||||||||
| 258 | 9 | ▶ | $object->errmode($params{'errmode'} || "die"); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'errmode'} || 'die'
MC/DC100%1/1
$params{'errmode'} || 'die'
$params{'errmode'}
Truth table100%2/2
A
A= $params{'errmode'}
| |||||||||||||||||||||||||||||||||
| 259 | 9 | ▶ | $object->resetafter($params{'resetafter'} || | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{'resetafter'} || $object->maxinterval * $object->adjustafter
MC/DC0%0/2
$params{'resetafter'} || $object->maxinterval * $object->adjustafter
$params{'resetafter'}
$object->maxinterval * $object->adjustafter
Truth table33%1/3
A || B
A= $params{'resetafter'}B= $object->maxinterval * $object->adjustafter
| |||||||||||||||||||||||||||||||||
| 260 | ($object->maxinterval*$object->adjustafter)); | ||||||||||||||||||||||||||||||||
| 261 | 9 | ▶ | $object->{"debug"}=($params{'debug'} || 0); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'debug'} || 0
MC/DC0%0/1
$params{'debug'} || 0
$params{'debug'}
Truth table50%1/2
A
A= $params{'debug'}
| |||||||||||||||||||||||||||||||||
| 262 | 9 | ▶ | $object->{"tail"}=($params{'tail'} || 0); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'tail'} || 0
MC/DC100%1/1
$params{'tail'} || 0
$params{'tail'}
Truth table100%2/2
A
A= $params{'tail'}
| |||||||||||||||||||||||||||||||||
| 263 | 9 | ▶ | $object->{"nowait"}=($params{'nowait'} || 0); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'nowait'} || 0
MC/DC0%0/1
$params{'nowait'} || 0
$params{'nowait'}
Truth table50%1/2
A
A= $params{'nowait'}
| |||||||||||||||||||||||||||||||||
| 264 | 9 | ▶ | $object->{"maxbuf"}=($params{'maxbuf'} || 16384); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'maxbuf'} || 16384
MC/DC0%0/1
$params{'maxbuf'} || 16384
$params{'maxbuf'}
Truth table50%1/2
A
A= $params{'maxbuf'}
| |||||||||||||||||||||||||||||||||
| 265 | 9 | ▶ | $object->{"name_changes_callback"}=($params{'name_changes'} || undef); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'name_changes'} || undef
MC/DC100%1/1
$params{'name_changes'} || undef
$params{'name_changes'}
Truth table100%2/2
A
A= $params{'name_changes'}
| |||||||||||||||||||||||||||||||||
| 266 | 9 | ▶ | if (defined $params{'reset_tail'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 267 | 0 | $object->{"reset_tail"} = $params{'reset_tail'}; | |||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||
| 269 | 9 | $object->{"reset_tail"} = -1; | |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | 9 | ▶ | $object->{'ignore_nonexistant'}=($params{'ignore_nonexistant'} || 0); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'ignore_nonexistant'} || 0
MC/DC0%0/1
$params{'ignore_nonexistant'} || 0
$params{'ignore_nonexistant'}
Truth table50%1/2
A
A= $params{'ignore_nonexistant'}
| |||||||||||||||||||||||||||||||||
| 272 | 9 | $object->{"lastread"}=0; | |||||||||||||||||||||||||||||||
| 273 | 9 | $object->{"sleepcount"}=0; | |||||||||||||||||||||||||||||||
| 274 | 9 | $object->{"lastcheck"}=0; | |||||||||||||||||||||||||||||||
| 275 | 9 | $object->{"lastreset"}=0; | |||||||||||||||||||||||||||||||
| 276 | 9 | $object->{"nextcheck"}=time(); | |||||||||||||||||||||||||||||||
| 277 | 9 | ▶ | if ($object->{"method"} eq "tail") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | 9 | $object->reset_pointers; | |||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | # $object->{curpos}=0; # ADDED 25May01: undef warnings when | ||||||||||||||||||||||||||||||||
| 281 | # $object->{endpos}=0; # starting up on a nonexistant file | ||||||||||||||||||||||||||||||||
| 282 | 9 | return $object; | |||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | # Sets position in file when first opened or after that when reset: | ||||||||||||||||||||||||||||||||
| 286 | # Sets {endpos} and {curpos} for current {handle} based on {tail}. | ||||||||||||||||||||||||||||||||
| 287 | # Sets {tail} to value of {reset_tail}; effect is that first call | ||||||||||||||||||||||||||||||||
| 288 | # uses {tail} and subsequent calls use {reset_tail}. | ||||||||||||||||||||||||||||||||
| 289 | sub position { | ||||||||||||||||||||||||||||||||
| 290 | 12 | ▶ | my $object=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 291 | 12 | $object->{"endpos"}=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 292 | 12 | ▶ | unless ($object->{"tail"}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 293 | $object->{endpos}=$object->{curpos}= | ||||||||||||||||||||||||||||||||
| 294 | 2 | sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 295 | } elsif ($object->{"tail"}<0) { | ||||||||||||||||||||||||||||||||
| 296 | 4 | $object->{endpos}=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 297 | 4 | $object->{curpos}=sysseek($object->{handle},0,SEEK_SET); | |||||||||||||||||||||||||||||||
| 298 | } else { | ||||||||||||||||||||||||||||||||
| 299 | 6 | my $crs=0; | |||||||||||||||||||||||||||||||
| 300 | 6 | my $maxlen=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 301 | 6 | ▶ | while ($crs<$object->{"tail"}+1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 302 | 6 | my $avlen=length($object->{"buffer"})/($crs+1); | |||||||||||||||||||||||||||||||
| 303 | 6 | ▶ | $avlen=80 unless $avlen; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | 6 | my $calclen=$avlen*$object->{"tail"}; | |||||||||||||||||||||||||||||||
| 305 | 6 | ▶ | $calclen=length($object->{tail})+1024 if $calclen<=length($object->{"tail"}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 306 | 6 | ▶ | $calclen=$maxlen if $calclen>$maxlen; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 307 | 6 | $object->{curpos}=sysseek($object->{handle},-$calclen,SEEK_END); | |||||||||||||||||||||||||||||||
| 308 | 6 | sysread($object->{handle},$object->{"buffer"}, | |||||||||||||||||||||||||||||||
| 309 | $calclen); | ||||||||||||||||||||||||||||||||
| 310 | 6 | ▶ | $object->{"buffer"} =~ s/\015\012/\n/g if $Is_Win32; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 311 | 6 | $object->{curpos}=sysseek($object->{handle},0,SEEK_CUR); | |||||||||||||||||||||||||||||||
| 312 | 6 | $crs=$object->{"buffer"}=~tr/\n//; | |||||||||||||||||||||||||||||||
| 313 | 6 | ▶ | last if ($calclen>=$maxlen); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||
| 315 | 6 | $object->{curpos}=sysseek($object->{handle},0,SEEK_CUR); | |||||||||||||||||||||||||||||||
| 316 | 6 | $object->{endpos}=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 317 | 6 | ▶ | if ($crs>$object->{"tail"}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 318 | 4 | my $toskip=$crs-$object->{"tail"}; | |||||||||||||||||||||||||||||||
| 319 | 4 | my $pos; | |||||||||||||||||||||||||||||||
| 320 | 4 | $pos=index($object->{"buffer"},"\n"); | |||||||||||||||||||||||||||||||
| 321 | 4 | ▶ | while (--$toskip) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 322 | 6 | $pos=index($object->{"buffer"},"\n",$pos+1); | |||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||
| 324 | 4 | $object->{"buffer"}=substr($object->{"buffer"},$pos+1); | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | 12 | $object->{"tail"}=$object->{"reset_tail"}; | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | # Tries to open or reopen the file; failure is an error unless | ||||||||||||||||||||||||||||||||
| 331 | # {ignore_nonexistant} is set. | ||||||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||||||
| 333 | # For a new file (ie, first time opened) just does some book-keeping | ||||||||||||||||||||||||||||||||
| 334 | # and calls position for initial position setup. Otherwise does some | ||||||||||||||||||||||||||||||||
| 335 | # checks whether file has been replaced, and if so changes to the new | ||||||||||||||||||||||||||||||||
| 336 | # file. (Calls position for reset setup). | ||||||||||||||||||||||||||||||||
| 337 | # | ||||||||||||||||||||||||||||||||
| 338 | # Always updates {lastreset} to current time. | ||||||||||||||||||||||||||||||||
| 339 | # | ||||||||||||||||||||||||||||||||
| 340 | sub reset_pointers { | ||||||||||||||||||||||||||||||||
| 341 | 11 | ▶ | my $object=shift @_; | ||||||||||||||||||||||||||||||
|
Subroutine
reset_pointers: called CC=11 SCAR=29.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 342 | 11 | $object->{lastreset} = time(); | |||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | 11 | my $st; | |||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | 11 | my $oldhandle=$object->{handle}; | |||||||||||||||||||||||||||||||
| 347 | 11 | my $newhandle=FileHandle->new; | |||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | 11 | my $newname; | |||||||||||||||||||||||||||||||
| 350 | 11 | ▶ | if ($oldhandle && $$object{'name_changes_callback'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$oldhandle and $object->{"name_changes_callback"}
MC/DC100%2/2
$oldhandle and $object->{"name_changes_callback"}
$oldhandle
$object->{"name_changes_callback"}
Truth table100%3/3
A and B
A= $oldhandleB= $object->{"name_changes_callback"}
| |||||||||||||||||||||||||||||||||
| 351 | 1 | $newname=$$object{'name_changes_callback'}(); | |||||||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||||||
| 353 | 10 | $newname=$object->input; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | 11 | ▶ | unless (open($newhandle,"<$newname")) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if ($object->{'ignore_nonexistant'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 358 | # If we have an oldhandle, leave endpos and curpos to what they | ||||||||||||||||||||||||||||||||
| 359 | # were, since oldhandle will still be the "current" handle elsewhere, | ||||||||||||||||||||||||||||||||
| 360 | # eg, checkpending. This also allows tailing a file which is removed | ||||||||||||||||||||||||||||||||
| 361 | # but still being written to. | ||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (!$oldhandle) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 363 | 0 | $object->{'endpos'}=0; | |||||||||||||||||||||||||||||||
| 364 | 0 | $object->{'curpos'}=0; | |||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||
| 366 | 0 | return; | |||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | 0 | $object->error("Error opening ".$object->input.": $!"); | |||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $object->{'endpos'}=0 unless defined($object->{'endpos'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $object->{'curpos'}=0 unless defined($object->{'curpos'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 371 | 0 | return; | |||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||
| 373 | 11 | binmode($newhandle); | |||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||
| 375 | 11 | ▶ | if (defined($oldhandle)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 376 | # If file has not been changed since last OK read do not do anything | ||||||||||||||||||||||||||||||||
| 377 | 2 | $st=stat($newhandle); | |||||||||||||||||||||||||||||||
| 378 | # lastread uses fractional time, stat doesn't. This can cause false | ||||||||||||||||||||||||||||||||
| 379 | # negatives. | ||||||||||||||||||||||||||||||||
| 380 | # If the file was changed the same second as it was last read, | ||||||||||||||||||||||||||||||||
| 381 | # we only reopen it if it's length has changed. The alternative is that | ||||||||||||||||||||||||||||||||
| 382 | # sometimes, files would be reopened needlessly, and with reset_tail | ||||||||||||||||||||||||||||||||
| 383 | # set to -1, we would see the whole file again. | ||||||||||||||||||||||||||||||||
| 384 | # Of course, if the file was removed the same second as when it was | ||||||||||||||||||||||||||||||||
| 385 | # last read, and replaced (within that second) with a file of equal | ||||||||||||||||||||||||||||||||
| 386 | # length, we're out of luck. I don't see how to fix this. | ||||||||||||||||||||||||||||||||
| 387 | 2 | ▶ | if ($st->mtime<=int($object->{'lastread'})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | if ($st->size==$object->{"curpos"}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 389 | 0 | $object->{lastread} = $st->mtime; | |||||||||||||||||||||||||||||||
| 390 | 0 | return; | |||||||||||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||||||||||||
| 392 | # will continue further to reset | ||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | 2 | $object->{handle}=$newhandle; | |||||||||||||||||||||||||||||||
| 397 | 2 | $object->position; | |||||||||||||||||||||||||||||||
| 398 | 2 | $object->{lastread} = $st->mtime; | |||||||||||||||||||||||||||||||
| 399 | 2 | close($oldhandle); | |||||||||||||||||||||||||||||||
| 400 | } else { # This is the first time we are opening this file | ||||||||||||||||||||||||||||||||
| 401 | 9 | $st=stat($newhandle); | |||||||||||||||||||||||||||||||
| 402 | 9 | $object->{handle}=$newhandle; | |||||||||||||||||||||||||||||||
| 403 | 9 | $object->position; | |||||||||||||||||||||||||||||||
| 404 | 9 | $object->{lastread}=$st->mtime; # for better estimate on initial read | |||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | sub checkpending { | ||||||||||||||||||||||||||||||||
| 411 | 24 | ▶ | my $object=shift @_; | ||||||||||||||||||||||||||||||
|
Subroutine
checkpending: called CC=7 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | 24 | my $old_lastcheck = $object->{lastcheck}; | |||||||||||||||||||||||||||||||
| 414 | 24 | $object->{"lastcheck"}=time; | |||||||||||||||||||||||||||||||
| 415 | 24 | ▶ | unless ($object->{handle}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 416 | 0 | $object->reset_pointers; | |||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | unless ($object->{handle}) { # This try did not open the file either | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 418 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | 24 | $object->{"endpos"}=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 423 | 24 | ▶ | if ($object->{"endpos"}<$object->{curpos}) { # file was truncated | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 424 | 1 | $object->position; | |||||||||||||||||||||||||||||||
| 425 | ▶ | } elsif (($object->{curpos}==$object->{"endpos"}) | |||||||||||||||||||||||||||||||
|
Condition100%3/3
$object->{"curpos"} == $object->{"endpos"} and &File::Tail::time() - $object->{"lastread"} > $object->{"resetafter"}
MC/DC100%2/2
$object->{"curpos"} == $object->{"endpos"} and &File::Tail::time() - $object->{"lastread"} > $object->{"resetafter"}
$object->{"curpos"} == $object->{"endpos"}
&File::Tail::time() - $object->{"lastread"} > $object->{"resetafter"}
Truth table100%3/3
A and B
A= $object->{"curpos"} == $object->{"endpos"}B= &File::Tail::time() - $object->{"lastread"} > $object->{"resetafter"}
| |||||||||||||||||||||||||||||||||
| 426 | && (time()-$object->{lastread})>$object->{'resetafter'}) { | ||||||||||||||||||||||||||||||||
| 427 | 2 | $object->reset_pointers; | |||||||||||||||||||||||||||||||
| 428 | 2 | $object->{"endpos"}=sysseek($object->{handle},0,SEEK_END); | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 24 | ▶ | if ($object->{"endpos"}-$object->{curpos}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 432 | 6 | sysseek($object->{handle},$object->{curpos},SEEK_SET); | |||||||||||||||||||||||||||||||
| 433 | 6 | readin($object,$object->{"endpos"}-$object->{curpos}); | |||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||
| 435 | 24 | return ($object->{"endpos"}-$object->{curpos}); | |||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||
| 438 | sub predict { | ||||||||||||||||||||||||||||||||
| 439 | 30 | ▶ | my $object=shift; | ||||||||||||||||||||||||||||||
|
Subroutine
predict: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 440 | 30 | my $crs=$object->{"buffer"}=~tr/\n//; # Count newlines in buffer | |||||||||||||||||||||||||||||||
| 441 | 30 | my @call=caller(1); | |||||||||||||||||||||||||||||||
| 442 | 30 | ▶ | return 0 if $crs; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | 24 | my $ttw=$object->{"nextcheck"}-time(); | |||||||||||||||||||||||||||||||
| 444 | 24 | ▶ | return $ttw if $ttw>0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 445 | 24 | ▶ | if (my $len=$object->checkpending) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 446 | 0 | readin($object,$len); | |||||||||||||||||||||||||||||||
| 447 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||
| 449 | 24 | ▶ | if ($object->{"sleepcount"}>$object->adjustafter) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 450 | 2 | $object->{"sleepcount"}=0; | |||||||||||||||||||||||||||||||
| 451 | 2 | $object->interval($object->interval*10); | |||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||
| 453 | 24 | $object->{"sleepcount"}++; | |||||||||||||||||||||||||||||||
| 454 | 24 | $object->{"nextcheck"}=time()+$object->interval; | |||||||||||||||||||||||||||||||
| 455 | 24 | return ($object->interval); | |||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | sub bitprint { | ||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | return "undef" unless defined($_[0]); | ||||||||||||||||||||||||||||||
|
Subroutine
bitprint: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 460 | 0 | return unpack("b*",$_[0]); | |||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | sub select { | ||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | my $object=shift @_ if ref($_[0]); | ||||||||||||||||||||||||||||||
|
Subroutine
select: not called CC=15 SCAR=54.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 465 | 0 | my ($timeout,@fds)=splice(@_,3); | |||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | $object=$fds[0] unless defined($object); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 467 | 0 | my ($savein,$saveout,$saveerr)=@_; | |||||||||||||||||||||||||||||||
| 468 | 0 | my ($minpred,$mustreturn); | |||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | if (defined($timeout)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 470 | 0 | $minpred=$timeout; | |||||||||||||||||||||||||||||||
| 471 | 0 | $mustreturn=time()+$timeout; | |||||||||||||||||||||||||||||||
| 472 | } else { | ||||||||||||||||||||||||||||||||
| 473 | 0 | $minpred=$fds[0]->predict; | |||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | 0 | foreach (@fds) { | |||||||||||||||||||||||||||||||
| 476 | 0 | my $val=$_->predict; | |||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | $minpred=$val if $minpred>$val; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||
| 479 | 0 | my ($nfound,$timeleft); | |||||||||||||||||||||||||||||||
| 480 | 0 | my @retarr; | |||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | while (defined($timeout)?(!$nfound && (time()<$mustreturn)):!$nfound) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not $nfound and &File::Tail::time() < $mustreturn
MC/DC0%0/2
not $nfound and &File::Tail::time() < $mustreturn
not $nfound
&File::Tail::time() < $mustreturn
Truth table0%0/3
not(A) and B
A= not $nfoundB= &File::Tail::time() < $mustreturn
| |||||||||||||||||||||||||||||||||
| 482 | # Restore bitmaps in case we called select before | ||||||||||||||||||||||||||||||||
| 483 | 0 | splice(@_,0,3,$savein,$saveout,$saveerr); | |||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 0 | ($nfound,$timeleft)=select($_[0],$_[1],$_[2],$minpred); | |||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | if (defined($timeout)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 490 | 0 | $minpred=$timeout; | |||||||||||||||||||||||||||||||
| 491 | } else { | ||||||||||||||||||||||||||||||||
| 492 | 0 | $minpred=$fds[0]->predict; | |||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||
| 494 | 0 | undef @retarr; | |||||||||||||||||||||||||||||||
| 495 | 0 | foreach (@fds) { | |||||||||||||||||||||||||||||||
| 496 | 0 | my $val=$_->predict; | |||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | $nfound++ unless $val; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | $minpred=$val if $minpred>$val; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | push(@retarr,$_) unless $val; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 503 | 0 | return ($nfound,$timeleft,@retarr); | |||||||||||||||||||||||||||||||
| 504 | } else { | ||||||||||||||||||||||||||||||||
| 505 | 0 | return $nfound; | |||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | sub readin { | ||||||||||||||||||||||||||||||||
| 510 | 7 | ▶ | my $crs; | ||||||||||||||||||||||||||||||
|
Subroutine
readin: called CC=9 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 511 | 7 | my ($object,$len)=@_; | |||||||||||||||||||||||||||||||
| 512 | 7 | ▶ | if (length($object->{"buffer"})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 513 | # this means the file was reset AND a tail -n was active | ||||||||||||||||||||||||||||||||
| 514 | 0 | $crs=$object->{"buffer"}=~tr/\n//; # Count newlines in buffer | |||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | return $crs if $crs; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||
| 517 | 7 | ▶ | $len=$object->{"maxbuf"} if ($len>$object->{"maxbuf"}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 518 | 7 | my $nlen=$len; | |||||||||||||||||||||||||||||||
| 519 | 7 | ▶ | while ($nlen>0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 520 | $len=sysread($object->{handle},$object->{"buffer"}, | ||||||||||||||||||||||||||||||||
| 521 | 7 | $nlen,length($object->{"buffer"})); | |||||||||||||||||||||||||||||||
| 522 | 7 | ▶ | $object->{"buffer"} =~ s/\015\012/\n/g if $Is_Win32; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||
| 524 | 7 | ▶ | last if $len==0; # Some busy filesystems return 0 sometimes, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 525 | # and never give anything more from then on if | ||||||||||||||||||||||||||||||||
| 526 | # you don't give them time to rest. This return | ||||||||||||||||||||||||||||||||
| 527 | # allows File::Tail to use the usual exponential | ||||||||||||||||||||||||||||||||
| 528 | # backoff. | ||||||||||||||||||||||||||||||||
| 529 | 7 | $nlen=$nlen-$len; | |||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||
| 531 | 7 | $object->{curpos}=sysseek($object->{handle},0,SEEK_CUR); | |||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||
| 533 | 7 | $crs=$object->{"buffer"}=~tr/\n//; | |||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||
| 535 | 7 | ▶ | if ($crs) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 536 | 7 | my $tmp=time; | |||||||||||||||||||||||||||||||
| 537 | 7 | ▶ | $object->{lastread}=$tmp if $object->{lastread}>$tmp; #??? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 538 | 7 | $object->interval(($tmp-($object->{lastread}))/$crs); | |||||||||||||||||||||||||||||||
| 539 | 7 | $object->{lastread}=$tmp; | |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||
| 541 | 7 | return ($crs); | |||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | sub read { | ||||||||||||||||||||||||||||||||
| 545 | 13 | ▶ | my $object=shift @_; | ||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=11 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 546 | 13 | my $len; | |||||||||||||||||||||||||||||||
| 547 | 13 | my $pending=$object->{"endpos"}-$object->{"curpos"}; | |||||||||||||||||||||||||||||||
| 548 | 13 | my $crs=$object->{"buffer"}=~m/\n/; | |||||||||||||||||||||||||||||||
| 549 | 13 | ▶ | while (!$pending && !$crs) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pending or $crs
MC/DC100%2/2
$pending or $crs
$pending
$crs
Truth table100%3/3
A or B
A= $pendingB= $crs
| |||||||||||||||||||||||||||||||||
| 550 | 6 | $object->{"sleepcount"}=0; | |||||||||||||||||||||||||||||||
| 551 | 6 | ▶ | while ($object->predict) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 552 | 24 | ▶ | if ($object->nowait) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 554 | 0 | return (); | |||||||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||||||
| 556 | 0 | return ""; | |||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||
| 559 | 24 | ▶ | sleep($object->interval) if ($object->interval>0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||
| 561 | 6 | $pending=$object->{"endpos"}-$object->{"curpos"}; | |||||||||||||||||||||||||||||||
| 562 | 6 | $crs=$object->{"buffer"}=~m/\n/; | |||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | 13 | ▶ | if (!length($object->{"buffer"}) || index($object->{"buffer"},"\n")<0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not length $object->{"buffer"} or index($object->{"buffer"}, "\n") == -1
MC/DC50%1/2
not length $object->{"buffer"} or index($object->{"buffer"}, "\n") == -1
not length $object->{"buffer"}
index($object->{"buffer"}, "\n") == -1
Truth table66%2/3
not(A) or B
A= not length $object->{"buffer"}B= index($object->{"buffer"}, "\n") == -1
| |||||||||||||||||||||||||||||||||
| 566 | 1 | readin($object,$pending); | |||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||
| 568 | 13 | ▶ | unless (wantarray) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 569 | my $str=substr($object->{"buffer"},0, | ||||||||||||||||||||||||||||||||
| 570 | 6 | 1+index($object->{"buffer"},"\n")); | |||||||||||||||||||||||||||||||
| 571 | $object->{"buffer"}=substr($object->{"buffer"}, | ||||||||||||||||||||||||||||||||
| 572 | 6 | 1+index($object->{"buffer"},"\n")); | |||||||||||||||||||||||||||||||
| 573 | 6 | return $str; | |||||||||||||||||||||||||||||||
| 574 | } else { | ||||||||||||||||||||||||||||||||
| 575 | 7 | my @str; | |||||||||||||||||||||||||||||||
| 576 | 7 | ▶ | while (index($object->{"buffer"},"\n")>-1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 577 | push(@str,substr($object->{"buffer"},0, | ||||||||||||||||||||||||||||||||
| 578 | 25 | 1+index($object->{"buffer"},"\n"))); | |||||||||||||||||||||||||||||||
| 579 | $object->{"buffer"}=substr($object->{"buffer"}, | ||||||||||||||||||||||||||||||||
| 580 | 25 | 1+index($object->{"buffer"},"\n")); | |||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||
| 583 | 7 | return @str; | |||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||
| 587 | 3 | 1; | |||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||
| 589 | __END__ | ||||||||||||||||||||||||||||||||