Mailing List Archive

1 2 3 4  View All
Re: Status of FileHandle functionality [ In reply to ]
>: >: I recall a patch being required for something like socket calls to
>: >: accept these. This is where I got the impression that there might
>: >: be other seldom-used routines that don't handle them, though probably
>: >: very few. Sorry for the fuzzy recall.
>:
>: >If so, it's a bug.
>:
>: Certainly there seem to be some in the case of things like
>: -f \*STDERR

>Really?

> open(FOO, "/etc/passwd");
> print -f \*FOO;

>prints 1.

hm... how come -f \*STD{IN,OUT,ERR} don't print 1?

--tom
Re: Status of FileHandle functionality [ In reply to ]
: hm... how come -f \*STD{IN,OUT,ERR} don't print 1?

Cause it's not attached to a regular file?

Larry
Re: Status of FileHandle functionality [ In reply to ]
>: hm... how come -f \*STD{IN,OUT,ERR} don't print 1?

>Cause it's not attached to a regular file?

oh, duh, but see nick's posting about -c vs -t inconsistencies
between STDIN and \*STDIN, etc.

--tom
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
: Alphabetical by first names.... sure... no problem. :-)

We can still sort it on last name. Seemed to work out okay last time. :-)

Or maybe we should just put something like

by Larry Wall
as told to Randal L. Schwartz
scripted for television by Stephen Potter

:-)

Larry
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
In <7771.814716991@mox>
On Thu, 26 Oct 95 08:16:31 MDT
Tom Christiansen <tchrist@mox.perl.com> writes:
>=silly> Now=comma as for the weight of a pint of water=comma is that a pound or a pound and=
>=silly> =20
>=silly> a quarter =semi-colon=minus=left-paren
>
> A pint's a pound the world around, except in England

Scotland, Wales, Eire, Australia? ;-)

> where a pint of warter's a pound and a quarter.
>
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
Larry Wall writes:
> : Alphabetical by first names.... sure... no problem. :-)
>
> We can still sort it on last name. Seemed to work out okay last time. :-)
>
> Or maybe we should just put something like
>
> by Larry Wall
> as told to Randal L. Schwartz
> scripted for television by Stephen Potter
>
> :-)
>
> Larry

Broadway musical by ...
Hollywood spectacle by ...

++jhi;
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
> Strange sunspot activity caused "Randal L. Schwartz" <merlyn@teleport.com> to w
> rite:
> | The book will have a camel on it, and a couple of familiar names alongside
> | Stephen's (we haven't duked out the order yet... :-).
>
> Duke it out? What's to duke out... it's gonna be alphabetical. ;-)
>
> -spp

By first name or last?

--
Jim Anderson Phone: (201)524-4076
Lehman Brothers, Inc. Fax: (201)524-5153
101 Hudson Street, 34th Floor E-mail: jander@lehman.com
Jersey City, NJ 07302 jander@jander.com
Re: Status of FileHandle functionality [ In reply to ]
In <12778.814726647@mox>
On Thu, 26 Oct 95 10:57:27 MDT
Tom Christiansen <tchrist@mox.perl.com> writes:
>
>hm... how come -f \*STD{IN,OUT,ERR} don't print 1?
>

#!/usr/local/bin/perl

foreach (\*STDIN,\*STDOUT,\*STDERR)
{
print "$_ -f=",-f($_)," -t=",-t($_)," -c=",-c($_),"\n";
}

foreach (STDIN,STDOUT,STDERR)
{
print "$_ -f=",-f($_)," -t=",-t($_)," -c=",-c($_),"\n";
}

Prints:

GLOB(0x8a1d0) -f= -t= -c=1
GLOB(0x8a230) -f= -t= -c=1
GLOB(0x8a26c) -f= -t= -c=1
STDIN -f= -t=1 -c=
STDOUT -f= -t=1 -c=
STDERR -f= -t=1 -c=


So \*STD are -c but not -t, but barewords are -t but not -c,
neither are -f
Re: Status of FileHandle functionality [ In reply to ]
On Thu, 26 Oct 1995 Nick.Ing-Simmons@tiuk.ti.com wrote:

> My working assumption is that the BAREWORD can be converted
> into *FileHandle::BAREWORD leaving %main::BAREWORD (or whatever) available.
>
> Issues are :
>
> - STDOUT etc. are global in some sense.
>
> - open(Package::BAREWORD,...)

Hmmm. Interesting. A bit tricky to pull off, but with a certain elegance.
STDOUT might be paired with %FileHandle::UNIVERSAL::STDOUT, or somesuch,
and Package::BAREWORD would get %FileHandle::Package::BAREWORD.

--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
Re: Status of FileHandle functionality [ In reply to ]
On Thu, 26 Oct 1995, Larry Wall wrote:

> : $L{a} = 3;
> : open(L,"<foo");
> :
> : Hmm... Waitasec... Actually _nothing happens_ at this point, because
> : FileHandle::new is never called for L. But if we presume some method that
> : modifies the hash, we can still make it happen:
> :
> : L->deleteonclose(1);
>
> That's a sticky semantic wicket.
>
> In that construct, the L is functioning as a class name, not as a *L.
> My original thought in Perl 5 was that bearword filehandles function
> like class names derived from FileHandle. There's no way to write a
> prototype for methods that forces the L to be treated as a *L rather
> than as %L::. Instead, there's chicanery in pp_method() to force
> L to be treated as a filehandle if *L happens to contain an IO.

I think I'm missing the point here, because calling a method like that
gives access to *main::L as surely as calling a method on a gensym'd
symbol gives access to an anonymous glob.


> : Larry, if you've read down this far, how about it? Does is seem feasible
> : to have a sub prototype like this:
> :
> : sub open (^$:$) {
> : my($fh,$filename,$mask) = @_;
> : }
>
> That works for functions, but not for methods.

That's what we are talking about here, so that's cool. That is an
exported open(), not a method.

> A prototype of (\*$:$) would do much the same thing, given the current
> implementation.

Yes, I can see that now. A "simple" isa-FileHandle check is then needed
on the glob, but that's user-level stuff.

> : > But we can have "use Open;" change the meaning of open() for
> : > one package so that open(BEARWERD,...) doesn't work but
> : > $fh=open("<foo") and $fh=open("foo",">>",0666) do. [.The
> : > module name has been changed to protect the innocent -- so
> : > don't argue "use Open" vs. "use IO::Stream::Handle" here :> ]
> :
> : :-) Right. Of course, I'm not sure if Larry's prototypes are up to
> : handling a single function that can be called as:
> :
> : open(BEARWORD,">a",0666) or die;
> : open(BEARWORD,"<a") or die;
> : $fh = open("<a");
> :
> : Oh! We still have to deal with such cruft as:
> :
> : $file = "/foo/bar";
> : open($file);
> :
> : I'm beginning to have sinking feelings at this point.
>
> You just can't have it both ways, is all.

Well... Can you say "function overloading"?

<ducking>

Well, maybe we don't need that, but what are your thoughts on this:

sub foo (\*$|$) {
if(@_==2) {
#...
} elsif(@_==1) {
#...
}
}

It seems that something along the lines of C<sub open (\*:$$|\$|$) {...}>
would take care of just about all open() variants, hienous (variants) or not.

I have no idea what you your prototype code looks like, but how difficult
would it actually be to put something like that in? If it fails a match,
instead of immediately choking, it would skip ahead to the next
alternative, and choke when it runs out.

> Larry


--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
Re: Status of FileHandle functionality [ In reply to ]
On Thu, 26 Oct 1995, Larry Wall wrote:

> : Um. Wouldn't this mean I couldn't use @STDOUT, %STDOUT, and
> : &STDOUT?? This would be worse when open(BEARWERD,...) is used
> : and eventually gets converted to a ref to glob and passed to
> : FileHandle::Method which excepts to have extra data around. Or
> : am I thinking all crooked again?
>
> I don't see how this is a problem, unless you've reblessed STDOUT into
> some other package that does anything with the other values. You don't
> derive from objects, you derive from classes. Objects are stolen from
> another class only be the constructors of the new class, which wouldn't
> be constructing STDOUT in general.

Ah, I see what you mean. So all this naughtiness with %FH would get
chucked into the "SuperFileHandle" class instead of FileHandle. If you
want the neat new features, you have to use the new syntax... I'd really
like for FileHandle to get the benefit of this stuff, but it does make a
simple solution for the first pass.

> : But I still think the answer to question (4) is "yes". You have a
> : single static hash for the class that you can look up objects in to
> : find that object's path, type, etc. Or is there a problem with this,
> : like static class data being a pain?
>
> It could conceivably cause package problems in a derived class, unless
> all data was accessed through methods.

Speed is the issue here, as always. A single hash lookup (heck, it could
even be an array lookup) for data seems acceptable. Multiple lookups
start straining things.

> Larry


--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
[. Sorry to come late to the discussion; I've just got back into town after
several days away, and am *way* behind on p5p - CB ]

Kenneth Albanowski writes:
| 1. Can we currently use blessed FileHandle objects everywhere bearword
| handles are accessible?

I think so, though I haven't tested it extensively.

| 2. Is it possible to write a class, IO::Handle, that can accept a wide
| range of constructors (as discussed) and return appropriate blessed
| objects of FileHandle decent? Who feels like writing this, if it hasn't
| already been written? Next goal: extend to have logical methods, so
| $fh->close() works, as does open(), print(), etc.

The basic ability is already there in the last set of patches, isn't it?
This class should do nothing except create the blessed reference.

| 3. Can destruction be handled sensibly, so open/close state can be
| tracked, and the FileHandle or IO::Handle destructor will only be called
| as needed, and not more times then necessary?
|
| 4. Is it currently possible to track extra data along with a FileHandle,
| say, a file name? Can anyone think of a way to implement the following
| code?
|
| use File::Temporary;
| $fh = new File::Temporary;
| print $fh "Hello, world!\n";
| close($fh);
| print $fh->name(); # prints "/tmp/012345"

No. It could be added pretty easily, either by keeping anonymous typeglobs and
creating a convention for storing data in other slots, or by using unused
members of a SVt_PVIO as a way to attach additional data.


| 5. Is it possible to override open() in such a way that this syntax is
| possible, and compatible with normal operations and method calls?

No. CORE::open (in fact, all the core file I/O routines) know about SVt_PVIOs.
At the moment, we don't have a way to specify this type from Perl, and we don't
have a replacement notion. Candidates discussed thus far include:
- an I/O type (whether ^fh or $fh = anonymous(IO)): type-checking in CORE
and user routines is direct; derived classes must create a reference
to an I/O-type object, or tie an object to an I/O type
- FileHandle class: type-checking in CORE and user routines is direct, but
derived classes are not possible
- class ISA FileHandle: type-checking in CORE and user routines is
indirect and quite expensive; derived classes can create any type of
reference they want, as long as the class into which it is blessed
ISA FileHandle
- don't bother: any object can be used for I/O; if it doesn't contain
a file descriptor in the right place, just return a runtime error

| $fh = open("<foo");
| #same as $fh = new FileHandle;open($fh,"<foo");

Both are possible now; neither is equivalent to C<open(FH,'foo')>.

| 6. What is the _simplest_ way to get tie() functionallity working on
| filehandles, that requires the fewest changes to perlCORE?

Hmm. How's this for a general description:
Decide on a way to identify an I/O handle, so we can tie to one. Add check for
package methods to CORE routines for <>, binmode, chmod, chown, close, fcntl,
file tests (stat), flock, getc, open (? - only if we allow ties by name),
print, printf, read, rename, seek, sysread, syswrite, tell, unlink, and write.
Socket methods are also a possibility. Other file-associated CORE routines
operate on names, except C<select>, which is so bound to C-style file
descriptors that I'm not sure whether or how it'd interact with tied objects.
Write a base package which supplies default methods, often in terms of other
methods, or just fatal stubs.

| 7. Are there any other questions?

7.1 How do we identify an I/O value?

7.2 How do we alias an I/O value into a typeglob (pretty much falls out of the
answer to 7.1)?

7.3 Do we set up a mechanism to tie IO handles, or do we just use ISA
FileHandle?

Regards,
Charles Bailey bailey@genetics.upenn.edu
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
On Sun, 29 Oct 1995, Charles Bailey wrote:

> [. Sorry to come late to the discussion; I've just got back into town after
> several days away, and am *way* behind on p5p - CB ]

No problem.

> Kenneth Albanowski writes:
> | 1. Can we currently use blessed FileHandle objects everywhere bearword
> | handles are accessible?
>
> I think so, though I haven't tested it extensively.

This has been hashed over a bit, and yes, most operators can handle it
(sorry, no pun intended it.

> | 2. Is it possible to write a class, IO::Handle, that can accept a wide
> | range of constructors (as discussed) and return appropriate blessed
> | objects of FileHandle decent? Who feels like writing this, if it hasn't
> | already been written? Next goal: extend to have logical methods, so
> | $fh->close() works, as does open(), print(), etc.
>
> The basic ability is already there in the last set of patches, isn't it?
> This class should do nothing except create the blessed reference.

Hmm. Well, this is where it gets complex, due to class heirarchies and
such. Yes, some bits are there, but even in Chip's patch, it's hard to
see them for POSIX. If I get the time, I intend to at least rough out a
complete set of IO:: modules, FileHandle support and all.

> No. It could be added pretty easily, either by keeping anonymous typeglobs and
> creating a convention for storing data in other slots, or by using unused
> members of a SVt_PVIO as a way to attach additional data.

Hash slots of anonymous typeglobs seems to be the best solution all
around. This however means that raw FileHandles, using "bearword" syntax
as they do, can't participate in this. The hash slot of "STDIN" is
%STDIN. This isn't particularly good.

I suppose we could move to additional members (perhaps even an HV*) in the
PVIO, but it seems that user-level code can do everything we want for now.

> | 5. Is it possible to override open() in such a way that this syntax is
> | possible, and compatible with normal operations and method calls?
>
> No. CORE::open (in fact, all the core file I/O routines) know about SVt_PVIOs.
> At the moment, we don't have a way to specify this type from Perl, and we don't
> have a replacement notion. Candidates discussed thus far include:
> - an I/O type (whether ^fh or $fh = anonymous(IO)): type-checking in CORE
> and user routines is direct; derived classes must create a reference
> to an I/O-type object, or tie an object to an I/O type
> - FileHandle class: type-checking in CORE and user routines is direct, but
> derived classes are not possible
> - class ISA FileHandle: type-checking in CORE and user routines is
> indirect and quite expensive; derived classes can create any type of
> reference they want, as long as the class into which it is blessed
> ISA FileHandle
> - don't bother: any object can be used for I/O; if it doesn't contain
> a file descriptor in the right place, just return a runtime error

Current thoughts on this involve using prototypes to let Perl
automatically convert this:

foo(FH,"abc");

into this:

foo(\*FH,"abc");

If I can talk Larry into providing multiple prototype for a single
function, then all the variants of CORE::open() could be directly supported.

As for FileHandle semantics, my proferred opinion is that the mechanism
you describe as "class ISA FileHandle" should be used -- anything that
ISA FileHandle (directly or indirectly) is usable as such.

Currently the built in IO functions seem to use something remeniscent of
"don't bother", and therefor I like "class ISA FileHandle" because it's
directly compatible, and is nicely OO.

This does however miss the point that FileHandles are real internal types
(PVIO). Unfortunately, Perl's OO doesn't line up with it's typing system,
so it's unclear what a "unified" solution would look like.

I am strongly _against_ ^FH notation, and would prefer FileHandles to be
more OO, not less OO.

> | $fh = open("<foo");
> | #same as $fh = new FileHandle;open($fh,"<foo");
>
> Both are possible now; neither is equivalent to C<open(FH,'foo')>.

Decidedly.

> | 6. What is the _simplest_ way to get tie() functionallity working on
> | filehandles, that requires the fewest changes to perlCORE?
>
> Hmm. How's this for a general description:
> Decide on a way to identify an I/O handle, so we can tie to one. Add check for
> package methods to CORE routines for <>, binmode, chmod, chown, close, fcntl,
> file tests (stat), flock, getc, open (? - only if we allow ties by name),
> print, printf, read, rename, seek, sysread, syswrite, tell, unlink, and write.
> Socket methods are also a possibility. Other file-associated CORE routines
> operate on names, except C<select>, which is so bound to C-style file
> descriptors that I'm not sure whether or how it'd interact with tied objects.
> Write a base package which supplies default methods, often in terms of other
> methods, or just fatal stubs.

My stated opinion on _this_ one is that tie() really shouldn't apply to
FileHandles, and instead should be implicit: any object that ISA
FileHandle will have methods named like "PRINT", "READ", and "TELL"
invoked at the right times.

Once again, this is more OO and less "internal". If filehandles were
given explicit names (^FH) then obviously a tie() style interface becomes
possible.

> | 7. Are there any other questions?
>
> 7.1 How do we identify an I/O value?

Right now, I'm all for ignoring this one, and letting the OO method call
syntax work out the details. (As per above.)

> 7.2 How do we alias an I/O value into a typeglob (pretty much falls out of the
> answer to 7.1)?

You mean put the PVIO part of a glob into an anonymous glob, without
transferring the rest? Interesting idea. One of Larry's comments about a
new "glob notation" seems appropriate here. Something like this:

*a{filehandle} = *STDIN{filehandle};

(Or something like that. Ideally, you get to use keys(), and in general
treat a glob just like a hash. The fallout with regards to regularlizing
access to symbol tables should be obvious.)

> 7.3 Do we set up a mechanism to tie IO handles, or do we just use ISA
> FileHandle?

As above, I'm for ISA FileHandle.

Actually, in writing this, I have realized that I really _am_ for more OO
stuff, and less "interalized types", which I never stated clearly before.

Hmm. For those that have read down this far, here's a question for you:
If Perl got compiled regexps, what sort of object would you like to see
them as? Entries into the symbol table (and thus with their own symbol
like "$" or "@"), or as references to a Regexp object?

If the former, then one might have code like this:

~a = /\S+/c; # ~a is the variable, /c means compile

if( /~a/ ) {
#...
}

If the latter:

$a = /\S+/c;

if( /$a/ ) {
#...
}

To round this out, what if we wanted to add "tie" functionality? In the
former, this might be:

tie(~a,MyRegexpType,...);

s/~a/abc/; #invokes MyRegexpType::SUBST(~a,"abc",\$_);

In the latter, the only suggestion I have is the same suggestion I have
for filehandles:

package Regexp;

sub SUBST {
my($regexpref,$replacement,$textref) = @_;
#...
}

sub MATCH { ... }

This however leads to exactly the same problem as with filehandles: you
can only "tie" the entire class of Regexp objects, or by inheritance,
particular objects _at creation_, and if you can't override creation,
then you can't change the class. Hence, this code:

$a = /\S+/c;

Is fated to _always_ producing an object of type "Regexp", and there is
no way of changing it (later on) to an object of type "MyRegexp" (which
ISA Regexp) so that it gets the new behavior. We'd have to say something
like this:

$a = new MyRegexp '\S+';

With named objects, and a real tie(), we can change the behaviour of
objects _after_ creation, and during there lifespan.

Next question: is such behaviour a good idea? For hashes, the answer seems
to be "yes", because that way you can attach, disconnect, and reconnect
hashs from various databases completely behind the back of some code.

For FileHandles, since the handle is referring to some outside unit
(perhaps a disk file, or a pipe, or a socket) it seems pretty clear that
changing behaviour (or at least changing tie()'s) in mid-steam is _not_
what we want. Or am I wrong here? What if the tie() was simply to install
a "tee connection" into the filehandle, so a debugging trace could be
made?

For Regexps, I have absolutely no idea how this would even be used in the
first place, so I can't offer much comment.

Thoughts?

> Regards,
> Charles Bailey bailey@genetics.upenn.edu
>

--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
Kenneth Albanowski writes:
|
| On Sun, 29 Oct 1995, Charles Bailey wrote:
|
| Hash slots of anonymous typeglobs seems to be the best solution all
| around. This however means that raw FileHandles, using "bearword" syntax
| as they do, can't participate in this. The hash slot of "STDIN" is
| %STDIN. This isn't particularly good.
|
| I suppose we could move to additional members (perhaps even an HV*) in the
| PVIO, but it seems that user-level code can do everything we want for now.

Actually, this seems a good time to rephrase one of the concerns I've had with
the way the I/O debate is going. Specifically, I understand that we _can_ cook
up an OO interface to files solely using Perl-mode code. Similarly, we _can_
define IO object as anything that ISA FileHandle (or whatever). What worries
me is that this is, at best, quite inefficient. While there's a lot to be said
for the argument that we implement a system in Perl as a prototype, and go back
and reimplement in C when the interface is settled, that model doesn't
translate well to parts of Perl which are probable performance bottlenecks.
I/O is just such an instance. While the OO model based on a FileHandle class
provides nice features, I'm uneasy about making it the _only_ way to extend
I/O. Perl's OO facilities, being 99+% runtime, aren't all that efficient, and
I'm worried that we're going to get a nice interface at the price of crippling
performance. For instance, if we decide an I/O object simply ISA FileHandle,
since Perl has no facility for determining inheritance at compile time, _every_
_call_ to C<print> triggers an @ISA lookup on the handle. How well does
caching of @ISA work? Finally, if we do start working with a Perl prototype,
what's the likelihood that some clever modules are going to take advantage of
implementation-specific details, leaving us with compatibility problems when we
do try to reimplement the intrface in a more efficient manner?

I'm far from expert on the internals related to method calls; if I'm starting
at shadows, please let me know.

| Current thoughts on this involve using prototypes to let Perl
| automatically convert this:
|
| foo(FH,"abc");
|
| into this:
|
| foo(\*FH,"abc");
|
| If I can talk Larry into providing multiple prototype for a single
| function, then all the variants of CORE::open() could be directly supported.

Sounds reasonable.

| As for FileHandle semantics, my proferred opinion is that the mechanism
| you describe as "class ISA FileHandle" should be used -- anything that
| ISA FileHandle (directly or indirectly) is usable as such.

Hmm. Apart the performance concerns I mentioned above, this also implies
a working ISA function, so Perl-level code could determine whether an
object ISA FileHandle.

| Currently the built in IO functions seem to use something remeniscent of
| "don't bother", and therefor I like "class ISA FileHandle" because it's
| directly compatible, and is nicely OO.

I agree that the current behavior isn't great. The silver lining is that,
since nothing's happening now, pretty much anything is compatible.

| This does however miss the point that FileHandles are real internal types
| (PVIO). Unfortunately, Perl's OO doesn't line up with it's typing system,
| so it's unclear what a "unified" solution would look like.
|
| I am strongly _against_ ^FH notation, and would prefer FileHandles to be
| more OO, not less OO.

I'm not sure that we should go one way xor the other. As you mention,
typing and OO derivation in Perl are largely orthogonal. There are
aspects of I/O management which would benefit from both, especially
if tying were available to cross the boundary between the two in
some ways.

Frankly, one of the assertions I've least understood in this thread
is, "I like the OO model, therefore don't add an I/O type". It seems
there are advantages to both, and implementing either won't interfere
with the other, so I don't understand the conflict. As an I/O user,
I'd generally prefer to work with an OO calling interface; as an I/O
implementor, I'd prefer a type interface.

| > | 6. What is the _simplest_ way to get tie() functionallity working on
| > | filehandles, that requires the fewest changes to perlCORE?
| >
| > Hmm. How's this for a general description:
| > Decide on a way to identify an I/O handle, so we can tie to one. Add check for
| > package methods to CORE routines for <>, binmode, chmod, chown, close, fcntl,
| > file tests (stat), flock, getc, open (? - only if we allow ties by name),
| > print, printf, read, rename, seek, sysread, syswrite, tell, unlink, and write.
| > Socket methods are also a possibility. Other file-associated CORE routines
| > operate on names, except C<select>, which is so bound to C-style file
| > descriptors that I'm not sure whether or how it'd interact with tied objects.
| > Write a base package which supplies default methods, often in terms of other
| > methods, or just fatal stubs.
|
| My stated opinion on _this_ one is that tie() really shouldn't apply to
| FileHandles, and instead should be implicit: any object that ISA
| FileHandle will have methods named like "PRINT", "READ", and "TELL"
| invoked at the right times.

The effect of either is pretty much the same -- we still need to identify the
pp_* functions affected, and insert either checks for tiedness or @ISA
traversals. It's just a question of interface and efficiency, as far as
I can see.

| Once again, this is more OO and less "internal". If filehandles were
| given explicit names (^FH) then obviously a tie() style interface becomes
| possible.
|
| > | 7. Are there any other questions?
| >
| > 7.1 How do we identify an I/O value?
|
| Right now, I'm all for ignoring this one, and letting the OO method call
| syntax work out the details. (As per above.)

How should we handle I/O method calls on a non-I/O object? Should the C code
detect that it's not ISA FileHandle and produce an error, or will we
need UNIVERSAL methods for all I/O calls which simply die (bleah)?

| > 7.2 How do we alias an I/O value into a typeglob (pretty much falls out of the
| > answer to 7.1)?
|
| You mean put the PVIO part of a glob into an anonymous glob, without
| transferring the rest? Interesting idea. One of Larry's comments about a
| new "glob notation" seems appropriate here. Something like this:
|
| *a{filehandle} = *STDIN{filehandle};
|
| (Or something like that. Ideally, you get to use keys(), and in general
| treat a glob just like a hash. The fallout with regards to regularlizing
| access to symbol tables should be obvious.)

Sounds good to me, in a number of cases. If the internal type of an I/O
handle is a GV, there's a problem here, but if it's an XPVIO, we're fine.

| Hmm. For those that have read down this far, here's a question for you:
| If Perl got compiled regexps, what sort of object would you like to see
| them as? Entries into the symbol table (and thus with their own symbol
| like "$" or "@"), or as references to a Regexp object?
|
| If the former, then one might have code like this:
|
| ~a = /\S+/c; # ~a is the variable, /c means compile
|
| if( /~a/ ) {
| #...
| }
|
| If the latter:
|
| $a = /\S+/c;
|
| if( /$a/ ) {
| #...
| }

I'm in the (apparent) minority in favor of more line noise. :-)
I _like_ the principle that $a represents a simple scalar value (already
violated by references, I realize), rather than one of a series of
semantically different things, whose only shared characteristic is the
singular number. For example, if complied regexps are objects of
class Regexp, then the meaning of C</$a/> is ambiguous; one needs to know
where $a came from to know whether a it's providing a string pattern or
a compiled regexp. (BTW, we also need to sort out eventually how
/$a$b/ [ or /~a~b/, or /~a$b/] will work.)

This is just an issue of aesthetics, though; I can certainly live with
whatever emerges.

| Next question: is such behaviour a good idea? For hashes, the answer seems
| to be "yes", because that way you can attach, disconnect, and reconnect
| hashs from various databases completely behind the back of some code.
|
| For FileHandles, since the handle is referring to some outside unit
| (perhaps a disk file, or a pipe, or a socket) it seems pretty clear that
| changing behaviour (or at least changing tie()'s) in mid-steam is _not_
| what we want. Or am I wrong here? What if the tie() was simply to install
| a "tee connection" into the filehandle, so a debugging trace could be
| made?

This ability would be useful for logging, vetting I/O, fallbacks, etc.
It also allows one to tie several (possibly localized) handles to the
same object, with the object's class methods tracking common state.

| For Regexps, I have absolutely no idea how this would even be used in the
| first place, so I can't offer much comment.

My guess is that this would provide the hook for such extensions as
inexact matching, gapped matching, weighted matching, constrained
substitition, etc. In other words, the tie doesn't affect the regexp
itself (unlike tied vars), but affects the actions in which the object
participates as a static value. Similar circumstances apply to I/O
handles and formats, from what I can see.

Regards,
Charles Bailey bailey@genetics.upenn.edu
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
In-Reply-To: <01HX2LZ106IK000A90@hmivax.humgen.upenn.edu>
I am not *too* enamoured with the 'Objects Or Bust' approach - forcing
everyone to use Objects just to do file I/O seems a bit draconian.
Please don't forget (with all due respect) that Perl is not a 'true' OO
language, and will never be so. The C++ community has gone through the
same process, taking a non OO language & adding OO functionality. It too
tried to make everyone do OO file I/O, with the IOStream library. Every
C++ book is full of
cin << somejunk << some other idiocy
etc. I can honestly say in 6-7 years of C++ experience, I have never
seen it used in a real system. People still use printf() as it is
a) established
b) easier to understand
c) does not rely on idiocies like pushing formats onto a I/O stream
OO is fine, but let's not pretend that it is the solution to everything.
I'd rather that filehandles were made into 'first class' types, and if
people want to put OO frippery on top, fine, as long as they don't force
everyone else to use it.

Alan Burlison aburlison@cix.compulink.co.uk
Re: "Line Noise" considered offensive (was Re: Proposal: ^HANDLE) [ In reply to ]
I wholeheartedly agree with Alan's sentiments.
The 'Objects or Bust' approach worries me as well.

To perhaps finish off this thread, I'll just say that those of us
who are in favour of "line noise" seem to agree on the following:

1. The addition of "line noise" for intrinsic types REGULARIZES
the language (sorry, couldn't help shouting :-).

2. Object Orientation (although wonderful) is not really an intrinsic
part of Perl -- no matter how you look at it, it is an "add on".
It feels wrong to be FORCED to use OO as the ONLY access to raw I/O
(although I agree that it could be made to look the same as it always
did for the usual cases).

3. Taking I/O down the OO route may make it difficult to address
efficiency concerns, now or later.

---
Paul Maisano
Australian Artificial Intelligence Institute

1 2 3 4  View All