File-SmartTail
view release on metacpan or search on metacpan
lib/File/SmartTail.pm view on Meta::CPAN
#
# Attempt to normalize path of prefix.
#
# If an arbitrary string (not the name of an existing file) is passed as -prefix,
# return input untouched, for backwards compatibility.
# If an existing filename is passed as -prefix (and for default of $0),
# resolve any symlinks in path.
#
sub normalize_prefix {
my $prefix = shift || $0;
-e $prefix or
return $prefix;
require File::Basename;
my ($name,$path,$suffix) = File::Basename::fileparse( $prefix );
$name = '' unless $name;
$path = '' unless $path;
$suffix = '' unless $suffix;
require Cwd;
$path = Cwd::abs_path( $path ) or
return $prefix;
$path =~ m{/$} or $path .= '/';
return $path . $name . $suffix;
}
=head1 Examples
=head2 Regular local file
use File::SmartTail;
$file = "/tmp/foo"
$tail = new File::SmartTail($file);
while($line = $tail->Tail) {
print $line;
}
or
use File::SmartTail;
$file = "/tmp/foo"
$tail = new File::SmartTail();
$tail->WatchFile(-file=>$file);
while($line = $tail->GetLine) {
print $line;
}
=head2 Regular remote file on two hosts
use File::SmartTail;
$file = "/tmp/foo";
$tail = new File::SmartTail;
$tail->WatchFile(-file=>$file, -type=>"UNIX-REMOTE", -host=>"guinness", -rmtopts
=>"-type UNIX");
$tail->WatchFile(-file=>$file, -type=>"UNIX-REMOTE", -host=>"corona", -rmtopts=>
"-type UNIX");
while($line = $tail->GetLine()) {
print $line;
}
=head2 Local file, with timeout
use File::SmartTail;
$file = "/tmp/foo";
$tail = new File::SmartTail;
$tail->WatchFile(-file=>$file, -type=>"UNIX", -timeout=>70);
while($line = $tail->GetLine()) {
print $line;
}
=head2 Remote file named by date, 4-digit year, having month directory
use File::SmartTail;
$file = "guinness:/tmp/foo20011114";
$tail = new File::SmartTail;
$tail->WatchFile(-file=>$file, -type=>"UNIX-REMOTE", -rmtopts=>'-date parsed -yrfmt 4 -monthdir ".." -type UNIX');
while($line = $tail->GetLine()) {
print $line;
=cut
1;
( run in 1.150 second using v1.01-cache-2.11-cpan-df04353d9ac )