line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DJabberd::XMLParser; |
2
|
1
|
|
|
1
|
|
6499
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
3
|
1
|
|
|
1
|
|
3
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
$VERSION = '1.00'; |
5
|
1
|
|
|
1
|
|
772
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use XML::SAX::Base; |
7
|
|
|
|
|
|
|
use base qw(XML::SAX::Base); |
8
|
|
|
|
|
|
|
use Carp; |
9
|
|
|
|
|
|
|
use Scalar::Util (); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $instance_count = 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my ($class, @params) = @_; |
15
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@params); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# libxml mode: |
18
|
|
|
|
|
|
|
if (1) { |
19
|
|
|
|
|
|
|
my $libxml = XML::LibXML->new; |
20
|
|
|
|
|
|
|
$libxml->set_handler($self); |
21
|
|
|
|
|
|
|
$self->{LibParser} = $libxml; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# this buys nothing but less noise when using Devel::Cycle: |
24
|
|
|
|
|
|
|
# make it a developer option? |
25
|
|
|
|
|
|
|
# Scalar::Util::weaken($self->{LibParser}); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$libxml->init_push; |
28
|
|
|
|
|
|
|
$self->{CONTEXT} = $libxml->{CONTEXT}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# expat mode: |
32
|
|
|
|
|
|
|
if (0) { |
33
|
|
|
|
|
|
|
#use XML::SAX::Expat::Incremental; |
34
|
|
|
|
|
|
|
my $parser = XML::SAX::Expat::Incremental->new(Handler => $self); |
35
|
|
|
|
|
|
|
$self->{expat} = $parser; |
36
|
|
|
|
|
|
|
$parser->parse_start; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$instance_count++; |
40
|
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
*parse_more = \&parse_chunk; |
44
|
|
|
|
|
|
|
sub parse_chunk { |
45
|
|
|
|
|
|
|
#my ($self, $chunk) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# 'push' (wrapper around _push) without context also works, |
48
|
|
|
|
|
|
|
# but _push (xs) is enough faster... |
49
|
|
|
|
|
|
|
$_[0]->{LibParser}->_push($_[0]->{CONTEXT}, |
50
|
|
|
|
|
|
|
$_[1]); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# expat version: |
53
|
|
|
|
|
|
|
# $_[0]->{expat}->parse_more($_[1]); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse_chunk_scalarref { |
57
|
|
|
|
|
|
|
#my ($self, $chunk) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# 'push' (wrapper around _push) without context also works, |
60
|
|
|
|
|
|
|
# but _push (xs) is enough faster... |
61
|
|
|
|
|
|
|
$_[0]->{LibParser}->_push($_[0]->{CONTEXT}, |
62
|
|
|
|
|
|
|
${$_[1]}); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# expat version: |
65
|
|
|
|
|
|
|
# $_[0]->{expat}->parse_more(${$_[1]}); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub finish_push { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
return 1 unless $self->{LibParser}; |
71
|
|
|
|
|
|
|
my $parser = delete $self->{LibParser}; |
72
|
|
|
|
|
|
|
eval { $parser->finish_push }; |
73
|
|
|
|
|
|
|
delete $self->{Handler}; |
74
|
|
|
|
|
|
|
delete $self->{CONTEXT}; |
75
|
|
|
|
|
|
|
return 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub DESTROY { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
$instance_count--; |
81
|
|
|
|
|
|
|
bless $self, 'XML::SAX::Base'; |
82
|
|
|
|
|
|
|
} |