Tom Christiansen wrote:
>
> >On Thu, Aug 03, 2000 at 06:40:30AM -0600, Tom Christiansen wrote:
> >> >Modify open() and opendir() to return filehandle objects
> >>
> >> Here are some things that that will be a problem for:
>
> >I did not see any that would be a problem.
>
> It's not as convenient.
I'm not sure I understand how it could be less convenient. Maybe the
term "filehandle object" is misleading and smacks of FileHandle. That
wasn't the intent. I propose a new name, "fileobject", that can refer to
something that handles any of these:
$fo1 = open "< $filename";
@file = <$fo1>;
$fo2 = open "| $pipe-to";
print $fo2 "$stuff\n";
$fo3 = open "$pipe-from |";
print while (<$fo3>);
Indeed, this was the intent of the original RFC. I'll revise it to
include this better terminology.
To give a better idea of where I'm going with this, here's a vision I've
come up with. I'm not claiming it's a good vision, but it's a vision.
Tidbits of this were mentioned in the RFC.
If we were to agree to make the basic syntax of open() something like:
$object = open [$filename], [$class];
There's a lot of cool stuff we could do. In the simplest "mostly looks
like Perl5" cases, open() can work like shown above. In fact, I'd be
plenty happy with just this, since it makes open() and opendir() look a
lot more Perlish to me.
However, if we extended this some more, there's some interesting
possibilities. Currently, if you want to open an FTP connection, you
have to do something like this:
use Net::FTP;
my $ftp = new Net::FTP ("ftp.perl.com");
$ftp->login("user", "pass");
And so on. Same for HTTP connections, etc. However, you could make
open() extensible, almost like tie() or new()[1] in that it can bind
objects to classes. So, to open a new FTP connection, maybe Perl6 could
let you do this:
$ftp = open "ftp.perl.com/pub", Net::FTP;
You see how this can be extended. If we wanted "builtin" HTTP file
access, we could say something like:
$http = open "http://www.perl.com/", HTTP::Request,
{ Request => GET };
@doc = <$http>;
Indeed, you could take this further and even say that opendir() was
really just a synonym for:
$dir = open "/my/dir", IO::DirObject; # theoretical
@files = grep !/^\..*/, (<$dir>); # no more readdir!
There's alot of assumptions here. This should not be taken as a
technical document, but a brain dump of creating a portable open().
Again, maybe it's a bad idea, or one that needs massive revision, but
it's an idea I wanted to get out there. There's persistence issues,
object issues, and much more if this was to be considered.
-Nate
[1] I *know* new() is "just a function", but you know what I mean. :-)