in reply to IO::File is gimp.
That's a great idea.
Because IO::File is a blessed symbol underneath the hood, I don't think was possible to store per-object state as well. Inside-out objects now make that fairly easy. It should be a fairly trivial exercise to subclass IO::File transparently with Class::InsideOut.
package IO::File::Stateful; use Class::InsideOut qw/public register id/; use base 'IO::File'; public 'input_record_separator' => my %IRS; sub new { my $class = shift; my $self = IO::File->new(@_); register( $self, $class ); $IRS{ id $self } = $/; # at time of creation return $self; } sub getline { my $self = shift; local $/ = $IRS{ id $self }; return $self->SUPER::getline(); } 1;
Of course, all the read/write subroutines for IO::Handle would need to be wrapped this same way. Output record separators could be done as well.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IO::File is gimp.
by chromatic (Archbishop) on Aug 12, 2007 at 20:54 UTC | |
by shmem (Chancellor) on Aug 12, 2007 at 21:53 UTC | |
by demerphq (Chancellor) on Aug 12, 2007 at 21:57 UTC |