Subject: | allowing Parse-Syslog to use IO::Handle as filehandle |
The included patch, against v1.03, allows Parse-Syslog to use a passed-in ref to something that isa(IO::Handle).
This is very useful if you have an object that (can) look like an IO::Handle, but can't be opened by filename, etc. For example, I am currently using IO::Scalar (from io-stringy) backed by a scalar to get syslog parsing from a string rather than a file.
The patch/functionality seems like it might be generally useful; I'd appreciate any feedback on it.
Thanks
--- libparse-syslog-perl-1.03.orig/lib/Parse/Syslog.pm
+++ libparse-syslog-perl-1.03/lib/Parse/Syslog.pm
@@ -2,6 +2,7 @@
use Carp;
use Symbol;
+use IO::File;
use Time::Local;
use strict;
use vars qw($VERSION);
@@ -83,9 +84,13 @@
$data{filetail} = 1;
$data{file} = $file;
}
- else {
- $data{file}=gensym;
- open($data{file}, "<$file") or croak "can't open $file: $!";
+ elsif($file->isa('IO::Handle'))
+ {
+ $data{file}=$file;
+ }
+ else
+ {
+ $data{file}=new IO::File("<$file") or croak "can't open $file: $!";
}
if(defined $data{locale}) {