File-SmartTail
view release on metacpan or search on metacpan
lib/File/SmartTail.pm view on Meta::CPAN
}
sub HostUser {
my %opts = @_;
my $return = undef;
if (%opts) {
my @array;
push @array, $opts{-host};
push @array, $opts{-user};
$return = \@array;
}
return $return;
}
sub Filename {
my %opts = @_;
my $return = undef;
if (%opts){
$return = $opts{-current};
}
return $return;
}
sub Key {
my %opts = @_;
my $return = undef;
if (%opts){
$return = $opts{-file};
}
return $return;
}
sub DateOpt {
my %opts = @_;
my $return = undef;
if (%opts){
$return = $opts{-date};
}
return $return;
}
sub RmtOpts {
my %opts = @_;
my $return = undef;
if (%opts) {
$return = $opts{-rmtopts};
}
return $return;
}
{
my $v;
sub LOG {
$v ||= require File::SmartTail::Logger && File::SmartTail::Logger::LOG();
}
}
#
# 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;
( run in 2.480 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )