line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
### |
3
|
|
|
|
|
|
|
# XML::Filter::BufferText - Filter to put all characters() in one event |
4
|
|
|
|
|
|
|
# Robin Berjon |
5
|
|
|
|
|
|
|
# 04/07/2003 - v1.01 |
6
|
|
|
|
|
|
|
# 26/11/2001 - v0.01 |
7
|
|
|
|
|
|
|
### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XML::Filter::BufferText; |
10
|
1
|
|
|
1
|
|
35378
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
11
|
1
|
|
|
1
|
|
7
|
use base qw(XML::SAX::Base); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
13756
|
|
12
|
1
|
|
|
1
|
|
26565
|
use vars qw($VERSION $AUTOLOAD); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
318
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
16
|
|
|
|
|
|
|
# now who said SAX was complex... |
17
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
18
|
4
|
|
|
4
|
1
|
265
|
sub characters { $_[0]->{_CharBuffer} .= $_[1]->{Data};} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub AUTOLOAD { |
21
|
5
|
|
|
5
|
|
1236
|
my $self = shift; |
22
|
5
|
|
|
|
|
9
|
my $data = shift; |
23
|
5
|
|
|
|
|
9
|
my $call = $AUTOLOAD; |
24
|
5
|
|
|
|
|
173
|
$call =~ s/^.*:://; |
25
|
5
|
50
|
|
|
|
18
|
return if $call eq 'DESTROY'; |
26
|
|
|
|
|
|
|
|
27
|
5
|
100
|
100
|
|
|
31
|
if (defined $self->{_CharBuffer} and length $self->{_CharBuffer}) { |
28
|
3
|
|
|
|
|
26
|
$self->SUPER::characters( { Data => $self->{_CharBuffer} } ); |
29
|
3
|
|
|
|
|
55
|
$self->{_CharBuffer} = ''; |
30
|
|
|
|
|
|
|
} |
31
|
5
|
|
|
|
|
11
|
$call = 'SUPER::' . $call; |
32
|
5
|
|
|
|
|
35
|
$self->$call($data); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
### AUTOLOAD and inheritance don't work all that well, this is a |
37
|
|
|
|
|
|
|
### workaround for that problem. |
38
|
|
|
|
|
|
|
sub start_document; sub end_document; sub start_element; |
39
|
|
|
|
|
|
|
sub end_element; sub processing_instruction; sub comment; |
40
|
|
|
|
|
|
|
sub skipped_entity; sub ignorable_whitespace; sub end_entity; |
41
|
|
|
|
|
|
|
sub start_entity; sub entity_reference; |
42
|
|
|
|
|
|
|
sub start_cdata; sub end_cdata; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
46
|
|
|
|
|
|
|
#`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
47
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
XML::Filter::BufferText - Filter to put all characters() in one event |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $h = SomeHandler->new; |
58
|
|
|
|
|
|
|
my $f = XML::Filter::BufferText->new( Handler => $h ); |
59
|
|
|
|
|
|
|
my $p = SomeParser->new( Handler => $f ); |
60
|
|
|
|
|
|
|
$p->parse; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This is a very simple filter. One common cause of grief (and programmer |
65
|
|
|
|
|
|
|
error) is that XML parsers aren't required to provide character events in one |
66
|
|
|
|
|
|
|
chunk. They can, but are not forced to, and most don't. This filter does the |
67
|
|
|
|
|
|
|
trivial but oft-repeated task of putting all characters into a single event. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Note that this won't help you cases such as: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
blah phubar |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
In the above case, given the interleaving comment, there will be two |
74
|
|
|
|
|
|
|
C events. This may be worked around in the future if there is |
75
|
|
|
|
|
|
|
demand for it. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
An interesting way to use this filter, instead of telling users to use it, |
78
|
|
|
|
|
|
|
is to return it from your handler's constructor, already configured and all. |
79
|
|
|
|
|
|
|
That'll make the buffering totally transparent to them (C |
80
|
|
|
|
|
|
|
does that). |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Robin Berjon, robin@knowscape.com |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (c) 2001-2002 Robin Berjon. All rights reserved. This program is |
89
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same |
90
|
|
|
|
|
|
|
terms as Perl itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SEE ALSO |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
XML::SAX::*, XML::Generator::*, XML::Handler::*, XML::Filter::* |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|