Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / XML / SAX / PurePerl / Reader.pm
CommitLineData
3fea05b9 1# $Id: Reader.pm,v 1.13 2008-08-05 12:37:13 grant Exp $
2
3package XML::SAX::PurePerl::Reader;
4
5use strict;
6use XML::SAX::PurePerl::Reader::URI;
7use Exporter ();
8
9use vars qw(@ISA @EXPORT_OK);
10@ISA = qw(Exporter);
11@EXPORT_OK = qw(
12 EOF
13 BUFFER
14 LINE
15 COLUMN
16 ENCODING
17 XML_VERSION
18);
19
20use constant EOF => 0;
21use constant BUFFER => 1;
22use constant LINE => 2;
23use constant COLUMN => 3;
24use constant ENCODING => 4;
25use constant SYSTEM_ID => 5;
26use constant PUBLIC_ID => 6;
27use constant XML_VERSION => 7;
28
29require XML::SAX::PurePerl::Reader::Stream;
30require XML::SAX::PurePerl::Reader::String;
31
32if ($] >= 5.007002) {
33 require XML::SAX::PurePerl::Reader::UnicodeExt;
34}
35else {
36 require XML::SAX::PurePerl::Reader::NoUnicodeExt;
37}
38
39sub new {
40 my $class = shift;
41 my $thing = shift;
42
43 # try to figure if this $thing is a handle of some sort
44 if (ref($thing) && UNIVERSAL::isa($thing, 'IO::Handle')) {
45 return XML::SAX::PurePerl::Reader::Stream->new($thing)->init;
46 }
47 my $ioref;
48 if (tied($thing)) {
49 my $class = ref($thing);
50 no strict 'refs';
51 $ioref = $thing if defined &{"${class}::TIEHANDLE"};
52 }
53 else {
54 eval {
55 $ioref = *{$thing}{IO};
56 };
57 undef $@;
58 }
59 if ($ioref) {
60 return XML::SAX::PurePerl::Reader::Stream->new($thing)->init;
61 }
62
63 if ($thing =~ /</) {
64 # assume it's a string
65 return XML::SAX::PurePerl::Reader::String->new($thing)->init;
66 }
67
68 # assume it is a uri
69 return XML::SAX::PurePerl::Reader::URI->new($thing)->init;
70}
71
72sub init {
73 my $self = shift;
74 $self->[LINE] = 1;
75 $self->[COLUMN] = 1;
76 $self->read_more;
77 return $self;
78}
79
80sub data {
81 my ($self, $min_length) = (@_, 1);
82 if (length($self->[BUFFER]) < $min_length) {
83 $self->read_more;
84 }
85 return $self->[BUFFER];
86}
87
88sub match {
89 my ($self, $char) = @_;
90 my $data = $self->data;
91 if (substr($data, 0, 1) eq $char) {
92 $self->move_along(1);
93 return 1;
94 }
95 return 0;
96}
97
98sub public_id {
99 my $self = shift;
100 @_ and $self->[PUBLIC_ID] = shift;
101 $self->[PUBLIC_ID];
102}
103
104sub system_id {
105 my $self = shift;
106 @_ and $self->[SYSTEM_ID] = shift;
107 $self->[SYSTEM_ID];
108}
109
110sub line {
111 shift->[LINE];
112}
113
114sub column {
115 shift->[COLUMN];
116}
117
118sub get_encoding {
119 my $self = shift;
120 return $self->[ENCODING];
121}
122
123sub get_xml_version {
124 my $self = shift;
125 return $self->[XML_VERSION];
126}
127
1281;
129
130__END__
131
132=head1 NAME
133
134XML::Parser::PurePerl::Reader - Abstract Reader factory class
135
136=cut