<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># $Id$

package XML::SAX::PurePerl::Reader;

use strict;
use XML::SAX::PurePerl::Reader::URI;
use Exporter ();

use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
    EOF
    BUFFER
    LINE
    COLUMN
    ENCODING
    XML_VERSION
);

use constant EOF =&gt; 0;
use constant BUFFER =&gt; 1;
use constant LINE =&gt; 2;
use constant COLUMN =&gt; 3;
use constant ENCODING =&gt; 4;
use constant SYSTEM_ID =&gt; 5;
use constant PUBLIC_ID =&gt; 6;
use constant XML_VERSION =&gt; 7;

require XML::SAX::PurePerl::Reader::Stream;
require XML::SAX::PurePerl::Reader::String;

if ($] &gt;= 5.007002) {
    require XML::SAX::PurePerl::Reader::UnicodeExt;
}
else {
    require XML::SAX::PurePerl::Reader::NoUnicodeExt;
}

sub new {
    my $class = shift;
    my $thing = shift;
    
    # try to figure if this $thing is a handle of some sort
    if (ref($thing) &amp;&amp; UNIVERSAL::isa($thing, 'IO::Handle')) {
        return XML::SAX::PurePerl::Reader::Stream-&gt;new($thing)-&gt;init;
    }
    my $ioref;
    if (tied($thing)) {
        my $class = ref($thing);
        no strict 'refs';
        $ioref = $thing if defined &amp;{"${class}::TIEHANDLE"};
    }
    else {
        eval {
            $ioref = *{$thing}{IO};
        };
        undef $@;
    }
    if ($ioref) {
        return XML::SAX::PurePerl::Reader::Stream-&gt;new($thing)-&gt;init;
    }
    
    if ($thing =~ /&lt;/) {
        # assume it's a string
        return XML::SAX::PurePerl::Reader::String-&gt;new($thing)-&gt;init;
    }
    
    # assume it is a    uri
    return XML::SAX::PurePerl::Reader::URI-&gt;new($thing)-&gt;init;
}

sub init {
    my $self = shift;
    $self-&gt;[LINE] = 1;
    $self-&gt;[COLUMN] = 1;
    $self-&gt;read_more;
    return $self;
}

sub data {
    my ($self, $min_length) = (@_, 1);
    if (length($self-&gt;[BUFFER]) &lt; $min_length) {
        $self-&gt;read_more;
    }
    return $self-&gt;[BUFFER];
}

sub match {
    my ($self, $char) = @_;
    my $data = $self-&gt;data;
    if (substr($data, 0, 1) eq $char) {
        $self-&gt;move_along(1);
        return 1;
    }
    return 0;
}

sub public_id {
    my $self = shift;
    @_ and $self-&gt;[PUBLIC_ID] = shift;
    $self-&gt;[PUBLIC_ID];
}

sub system_id {
    my $self = shift;
    @_ and $self-&gt;[SYSTEM_ID] = shift;
    $self-&gt;[SYSTEM_ID];
}

sub line {
    shift-&gt;[LINE];
}

sub column {
    shift-&gt;[COLUMN];
}

sub get_encoding {
    my $self = shift;
    return $self-&gt;[ENCODING];
}

sub get_xml_version {
    my $self = shift;
    return $self-&gt;[XML_VERSION];
}

1;

__END__

=head1 NAME

XML::Parser::PurePerl::Reader - Abstract Reader factory class

=cut
</pre></body></html>