in reply to Re^2: Best way to check if something is a file handle?
in thread Best way to check if something is a file handle?
A whole module that does what I want ... in some cases I'd want it to return true.
That is only the case if you define "what you want" as: "What my newly minted module does."
But, what does a.n.other user actually need? And does your is_filehandle() actually supply it?
That is, someone is writing a module that accepts a "file handle" as a input argument, and they want to know if what they've been given, is acceptable for their purpose. That means they can either read from it; write to it; or both. And your module fails to detect that information.
#! perl -slw use strict; use IO::Detect qw[ is_filehandle ]; sub funcTakesIO1 { my $fh = shift; if( is_filehandle( $fh ) ) { print $fh 'Bang!'; } return; } sub funcTakesIO2 { my $fh = shift; if( is_filehandle( $fh ) ) { return <$fh>; } return; } eval { funcTakesIO1( \*STDIN ); } or warn "IO::Detect detected the wrong thing"; eval { funcTakesIO2( \*STDOUT ); } or warn "IO::Detect detected the wrong thing"; __END__ C:\test>junk5 Filehandle STDIN opened only for input at C:\test\junk5.pl line 9. IO::Detect detected the wrong thing at C:\test\junk5.pl line 24. Filehandle STDOUT opened only for output at C:\test\junk5.pl line 18. IO::Detect detected the wrong thing at C:\test\junk5.pl line 28.
What the user actually requires in that situation is something like siphylis' Filehandle::Fmode, which has been around for a few years and effectively renders your module redundant.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Best way to check if something is a file handle?
by tobyink (Canon) on Jul 09, 2012 at 22:44 UTC | |
by BrowserUk (Patriarch) on Jul 09, 2012 at 23:50 UTC | |
by tobyink (Canon) on Jul 10, 2012 at 21:55 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2012 at 22:55 UTC | |
by tobyink (Canon) on Jul 11, 2012 at 00:18 UTC | |
|