File Coverage

blib/lib/XML/SAX/ExpatNB.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package XML::SAX::ExpatNB;
4 2     2   1905 use base qw/XML::SAX::Expat::Incremental/;
  2         6  
  2         2039  
5              
6             use strict;
7             #use warnings;
8              
9             use vars qw/$VERSION/;
10             $VERSION = "0.01";
11              
12             use IO::Handle ();
13             use Scalar::Util qw/blessed/;
14             use Carp qw/croak/;
15              
16             sub parse {
17             my $p = shift;
18             my $opts = $p->get_options(@_);
19            
20             if ($p->{Parent}){
21             return $p->{Parent}->parse($opts);
22             } else {
23             if (defined $opts->{Source}{ByteStream}){
24             if ($opts->{ReadOnce}){
25             return $p->_parse_bytestream_once($opts->{Source}{ByteStream}, $opts->{ReadOnce});
26             } else {
27             return $p->_parse_bytestream($opts->{Source}{ByteStream});
28             }
29             } else {
30             croak "Nonblocking reads only make sense if you're giving me file handles, y'know (well, actually sockets). Use parse_file";
31             }
32             }
33             }
34              
35             sub parse_once {
36             my $p = shift;
37             my $fh = shift;
38             my $bytes = shift || 4096;
39             $p->parse_file($fh, @_, ReadOnce => $bytes);
40             }
41              
42             sub _parse_bytestream {
43             my $p = shift;
44             my $fh = shift;
45             $fh = IO::Handle->new_from_fd($fh, "<") unless blessed $fh;
46              
47             $fh->blocking(0);
48              
49             while($fh->sysread(my $buffer, 4096)){
50             $p->_parse_string($buffer);
51             }
52             }
53              
54             sub _parse_bytestream_once {
55             my $p = shift;
56             my $fh = shift;
57             $fh = IO::Handle->new_from_fd($fh, "<") unless blessed $fh;
58             my $bytes = shift;
59              
60             $fh->blocking(0);
61              
62             my $buffer;
63             $fh->sysread($buffer, $bytes)
64             and $p->_parse_string($buffer);
65             }
66              
67             __PACKAGE__
68              
69             __END__