Skip Menu |

This queue is for tickets about the Parse-Syslog CPAN distribution.

Report information
The Basics
Id: 14107
Status: resolved
Priority: 0/
Queue: Parse-Syslog

People
Owner: Nobody in particular
Requestors: rudolph [...] usyd.edu.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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}) {
From: rudolph [...] usyd.edu.au
[guest - Thu Aug 11 01:56:20 2005]: Show quoted text
> The included patch, against v1.03, allows Parse-Syslog to use a > passed-in ref to something that isa(IO::Handle).
Apologies, the previous patch is incorrect; it omitted a vital check. This one should be better. 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(ref($file) && ($file->isa('IO::Handle'))) + { + $data{file}=$file; + } + else + { + $data{file}=new IO::File("<$file") or croak "can't open $file: $!"; } if(defined $data{locale}) {
Hi, Would the following simplified patch also work? --- lib/Parse/Syslog.pm 12 Sep 2005 11:22:44 -0000 1.18 +++ lib/Parse/Syslog.pm 17 Nov 2005 20:29:08 -0000 @@ -84,6 +84,9 @@ $data{filetail} = 1; $data{file} = $file; } + elsif(ref($file) && ($file->isa('IO::Handle'))) { + $data{file}=$file; + } else { $data{file}=gensym; open($data{file}, "<$file") or croak "can't open $file: $!";
Parse::Syslog 1.09 supports passing IO::Handle as filehandle