1 # $Id: Stream.pm,v 1.7 2005-10-14 20:31:20 matt Exp $
3 package XML::SAX::PurePerl::Reader::Stream;
8 use XML::SAX::PurePerl::Reader qw(
16 use XML::SAX::Exception;
18 @ISA = ('XML::SAX::PurePerl::Reader');
20 # subclassed by adding 1 to last element
22 use constant BUFFER_SIZE => 4096;
27 XML::SAX::PurePerl::Reader::set_raw_stream($ioref);
29 @parts[FH, LINE, COLUMN, BUFFER, EOF, XML_VERSION] =
30 ($ioref, 1, 0, '', 0, '1.0');
31 return bless \@parts, $class;
37 my $bytesread = read($self->[FH], $buf, BUFFER_SIZE);
39 $self->[BUFFER] .= $buf;
42 elsif (defined($bytesread)) {
47 throw XML::SAX::Exception::Parse(
48 Message => "Error reading from filehandle: $!",
55 my $discarded = substr($self->[BUFFER], 0, $_[0], '');
57 # Wish I could skip this lot - tells us where we are in the file
58 my $lines = $discarded =~ tr/\n//;
59 $self->[LINE] += $lines;
61 $discarded =~ /\n([^\n]*)$/;
62 $self->[COLUMN] = length($1);
65 $self->[COLUMN] += $_[0];
72 # warn("set encoding to: $encoding\n");
73 XML::SAX::PurePerl::Reader::switch_encoding_stream($self->[FH], $encoding);
74 XML::SAX::PurePerl::Reader::switch_encoding_string($self->[BUFFER], $encoding);
75 $self->[ENCODING] = $encoding;