File Coverage

blib/lib/XML/SAX/PurePerl/Reader.pm
Criterion Covered Total %
statement 59 84 70.2
branch 8 18 44.4
condition 0 3 0.0
subroutine 20 23 86.9
pod 0 10 0.0
total 87 138 63.0


line stmt bran cond sub pod time code
1             # $Id$
2              
3             package XML::SAX::PurePerl::Reader;
4              
5 12     12   66 use strict;
  12         21  
  12         456  
6 12     12   8213 use XML::SAX::PurePerl::Reader::URI;
  12         42  
  12         849  
7 12     12   78 use Exporter ();
  12         28  
  12         374  
8              
9 12     12   68 use vars qw(@ISA @EXPORT_OK);
  12         23  
  12         1084  
10             @ISA = qw(Exporter);
11             @EXPORT_OK = qw(
12             EOF
13             BUFFER
14             LINE
15             COLUMN
16             ENCODING
17             XML_VERSION
18             );
19              
20 12     12   79 use constant EOF => 0;
  12         24  
  12         911  
21 12     12   66 use constant BUFFER => 1;
  12         29  
  12         511  
22 12     12   819 use constant LINE => 2;
  12         25  
  12         544  
23 12     12   75 use constant COLUMN => 3;
  12         22  
  12         896  
24 12     12   60 use constant ENCODING => 4;
  12         25  
  12         520  
25 12     12   59 use constant SYSTEM_ID => 5;
  12         19  
  12         511  
26 12     12   66 use constant PUBLIC_ID => 6;
  12         18  
  12         563  
27 12     12   60 use constant XML_VERSION => 7;
  12         33  
  12         3184  
28              
29             require XML::SAX::PurePerl::Reader::Stream;
30             require XML::SAX::PurePerl::Reader::String;
31              
32             if ($] >= 5.007002) {
33             require XML::SAX::PurePerl::Reader::UnicodeExt;
34             }
35             else {
36             require XML::SAX::PurePerl::Reader::NoUnicodeExt;
37             }
38              
39             sub new {
40 0     0 0 0 my $class = shift;
41 0         0 my $thing = shift;
42            
43             # try to figure if this $thing is a handle of some sort
44 0 0 0     0 if (ref($thing) && UNIVERSAL::isa($thing, 'IO::Handle')) {
45 0         0 return XML::SAX::PurePerl::Reader::Stream->new($thing)->init;
46             }
47 0         0 my $ioref;
48 0 0       0 if (tied($thing)) {
49 0         0 my $class = ref($thing);
50 12     12   81 no strict 'refs';
  12         27  
  12         8047  
51 0 0       0 $ioref = $thing if defined &{"${class}::TIEHANDLE"};
  0         0  
52             }
53             else {
54 0         0 eval {
55 0         0 $ioref = *{$thing}{IO};
  0         0  
56             };
57 0         0 undef $@;
58             }
59 0 0       0 if ($ioref) {
60 0         0 return XML::SAX::PurePerl::Reader::Stream->new($thing)->init;
61             }
62            
63 0 0       0 if ($thing =~ /
64             # assume it's a string
65 0         0 return XML::SAX::PurePerl::Reader::String->new($thing)->init;
66             }
67            
68             # assume it is a uri
69 0         0 return XML::SAX::PurePerl::Reader::URI->new($thing)->init;
70             }
71              
72             sub init {
73 0     0 0 0 my $self = shift;
74 0         0 $self->[LINE] = 1;
75 0         0 $self->[COLUMN] = 1;
76 0         0 $self->read_more;
77 0         0 return $self;
78             }
79              
80             sub data {
81 24625     24625 0 37875 my ($self, $min_length) = (@_, 1);
82 24625 100       212575 if (length($self->[BUFFER]) < $min_length) {
83 105         357 $self->read_more;
84             }
85 24625         141318 return $self->[BUFFER];
86             }
87              
88             sub match {
89 3006     3006 0 5299 my ($self, $char) = @_;
90 3006         5456 my $data = $self->data;
91 3006 100       58560 if (substr($data, 0, 1) eq $char) {
92 3005         9831 $self->move_along(1);
93 3005         13155 return 1;
94             }
95 1         5 return 0;
96             }
97              
98             sub public_id {
99 25     25 0 58 my $self = shift;
100 25 100       198 @_ and $self->[PUBLIC_ID] = shift;
101 25         83 $self->[PUBLIC_ID];
102             }
103              
104             sub system_id {
105 25     25 0 51 my $self = shift;
106 25 100       125 @_ and $self->[SYSTEM_ID] = shift;
107 25         128 $self->[SYSTEM_ID];
108             }
109              
110             sub line {
111 3     3 0 15 shift->[LINE];
112             }
113              
114             sub column {
115 3     3 0 29 shift->[COLUMN];
116             }
117              
118             sub get_encoding {
119 12     12 0 24 my $self = shift;
120 12         62 return $self->[ENCODING];
121             }
122              
123             sub get_xml_version {
124 0     0 0   my $self = shift;
125 0           return $self->[XML_VERSION];
126             }
127              
128             1;
129              
130             __END__