IO::Tokenized::File - Extension of IO::File allowing tokenized input


IO-Tokenized documentation Contained in the IO-Tokenized distribution.

Index


Code Index:

NAME

Top

IO::Tokenized::File - Extension of IO::File allowing tokenized input

SYNOPSIS

Top

  my $fh = IO::Tokenized::File->new();
  $fh->setparser([num => qr/\d+/],
                 [ident => qr/[a-z_][a-z0-9_]],
                 [op => qr![+*/-]!,\&opname]);

  $fh->open('tokenfile') || die "Can't open 'tokenfile': $1";

  while ($t = $fh->gettoken()) {
    ... do something smart...
  }

  $fh->close();




DESCRIPTION

Top

IO::Tokenized::File adds the methods provided by IO::Tokenized to IO::File objects. See IO::Tokenized for details about how the tokens are specified and returned.

METHODS

Top

IO::Tokenized::File inherits both from IO::tokenized and IO::File, so that methods from both classes are available to IO::Tokenized::File objects.

IO::Tokenized::File redefines the following methods:

* new([$filename[,@tokens]])

The new method is redefined so as to call both IO::File::new (passing to $filename if it is defined) and IO::Tokenized::new (passing to it the @tokens parameter).

* open($filename)

The open method from IO::File is redefined so that only opening for input is allowed: requestes for other kind of opening are silently converted to oepning for input (this is a bug).

SEE ALSO

Top

IO::Tokenized and IO::File.

AUTHOR

Top

Leo Cacciari, <hobbit@cpan.org>

COPYRIGHT AND LICENSE

Top


IO-Tokenized documentation Contained in the IO-Tokenized distribution.

package IO::Tokenized::File;
use strict;
use base qw(IO::Tokenized IO::File);
use vars qw($VERSION);

use Carp;

$VERSION = '0.05';


# new has the following synopsis:
# IO::Tokenized::File->new([$tokens [,$filename]])

sub new {
  my $class = shift;
  my ($filename,@tokens) = @_;
  my $self = defined $filename ? IO::File->new($filename): IO::File->new();
  $self = IO::Tokenized->new($self,@tokens);
  bless $self,$class;
}

# redefine so that only opening for input is allowed
sub open {
  my $self = shift;
  my ($filename) = @_; #silently ignore other parameters
  $self->SUPER::open($filename,"r");
}

1;

__END__