line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Essex::Event; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 0.000_1; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
XML::Essex::Event - ... |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
The base event class, also used for unknown event types. |
14
|
|
|
|
|
|
|
Stringifies as $event->type . "()" to indicate an |
15
|
|
|
|
|
|
|
event that has no natural way to represented in XML, or for ones that |
16
|
|
|
|
|
|
|
haven't been handled yet in Essex. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 Methods |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=over |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
10
|
|
|
10
|
|
8132
|
use XML::Essex::Constants qw( debugging ); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
79
|
|
27
|
|
|
|
|
|
|
|
28
|
10
|
|
|
10
|
|
56
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
1474
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use overload ( |
31
|
|
|
|
|
|
|
'""' => \&_stringify, |
32
|
6
|
|
|
6
|
|
101
|
"cmp" => sub { "$_[0]" cmp "$_[1]" }, |
33
|
0
|
|
|
0
|
|
0
|
"==" => sub { "$_[0]" == "$_[1]" }, |
34
|
10
|
|
|
10
|
|
16589
|
); |
|
10
|
|
|
|
|
18891
|
|
|
10
|
|
|
|
|
158
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
XML::Event->new( a => 1, b => 2 ); |
39
|
|
|
|
|
|
|
XML::Event->new( { a => 1, b => 2 } ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
## in a subclass: |
42
|
|
|
|
|
|
|
sub new { |
43
|
|
|
|
|
|
|
my $self = shift->SUPER::new( @_ ); |
44
|
|
|
|
|
|
|
... |
45
|
|
|
|
|
|
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
A generic constructor. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
If a single value is passed in, a reference to it is kept. This must |
51
|
|
|
|
|
|
|
be a HASH for all builtin objects. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
If an even number of parameters is passed in, treats them as key => |
54
|
|
|
|
|
|
|
value pairs and creates a HASH around them. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# $self is a blessed reference to a SCALAR containing another reference |
59
|
|
|
|
|
|
|
# to the data. This double indirection serves several purposes: |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# 1. It allows us to overload %{} on $self and still easily get at |
62
|
|
|
|
|
|
|
# the object's data. |
63
|
|
|
|
|
|
|
# 2. It allows upstream filters to send us blessed, tied or overloaded |
64
|
|
|
|
|
|
|
# objects that we operate on and pass on. |
65
|
|
|
|
|
|
|
# 3. It reduces copying, at the cost of increasing the cost of |
66
|
|
|
|
|
|
|
# dereferencing. As many SAX operations are pass through, this may |
67
|
|
|
|
|
|
|
# be a win in most cases. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
34
|
|
|
34
|
1
|
4075
|
my $proto = shift; |
71
|
|
|
|
|
|
|
|
72
|
34
|
100
|
|
|
|
209
|
my $self = @_ == 1 |
|
|
100
|
|
|
|
|
|
73
|
|
|
|
|
|
|
? UNIVERSAL::isa( $_[0], "XML::Essex::Event" ) |
74
|
|
|
|
|
|
|
? $_[0]->clone |
75
|
|
|
|
|
|
|
: \$_[0] |
76
|
|
|
|
|
|
|
: \{ @_ }; |
77
|
|
|
|
|
|
|
|
78
|
34
|
|
33
|
|
|
241
|
bless $self, ref $proto || $proto; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item isa |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Accepts shorthand; if the object's class starts with |
84
|
|
|
|
|
|
|
"XML::Essex::Event::", the parameter is checked against the string after |
85
|
|
|
|
|
|
|
"XML::Essex::Event::". So a XML::Essex::Event::foo->isa( "foo" ) is |
86
|
|
|
|
|
|
|
true (assuming it really is true; in other words, assuming that its @ISA |
87
|
|
|
|
|
|
|
is set properly). |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub isa { |
92
|
17
|
|
|
17
|
1
|
661
|
my $self = shift; |
93
|
17
|
|
33
|
|
|
53
|
my $class = ref $self || $self; |
94
|
|
|
|
|
|
|
|
95
|
17
|
|
66
|
|
|
266
|
return (1 |
96
|
|
|
|
|
|
|
&& substr( $class, 0, 19 ) eq "XML::Essex::Event::" |
97
|
|
|
|
|
|
|
&& substr( $class, 19 ) eq $_[0] |
98
|
|
|
|
|
|
|
) || $self->SUPER::isa( @_ ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item clone |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $clone = $e->clone; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Does a deep copy of an event. Any events that require a deep copy |
106
|
|
|
|
|
|
|
must overload this to provide it, the default action is to just copy the |
107
|
|
|
|
|
|
|
main HASH. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub clone { |
112
|
7
|
|
|
7
|
1
|
11
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
7
|
|
|
|
|
40
|
bless \{ %$$self }, ref $self; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item type |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Strips all characters up to the "::" and returns the remainder, so, for |
120
|
|
|
|
|
|
|
the XML::Essex::start_document class, this returns "start_document". |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This I return a valid SAX event name, it is used to figure out |
123
|
|
|
|
|
|
|
how to serialize most event objects. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is overloaded in most classes for speed and to allow subclasses to |
126
|
|
|
|
|
|
|
tweak the behavior of a class and still be reported as the proper type. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub type { |
131
|
0
|
|
|
0
|
1
|
0
|
( my $r = ref shift ) =~ s/.*:://; |
132
|
0
|
|
|
|
|
0
|
$r |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
4
|
|
|
4
|
|
411
|
sub _stringify { shift->type() . "()" } |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item generate_SAX |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$e->generate_SAX( $handler ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Emits the SAX event(s) necessary to serialize this event object |
142
|
|
|
|
|
|
|
and send them to $handler. $handler will always be defined. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Uses the C method to figure out what to send. Some classes |
145
|
|
|
|
|
|
|
(notably XML::Essex::characters) overload this for various reasons. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Assumes scalar context (which should not cause problems). |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# scalar context is assumed in start_element::generate_SAX. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub generate_SAX { |
154
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
155
|
3
|
|
|
|
|
4
|
my ( $h ) = @_; |
156
|
|
|
|
|
|
|
|
157
|
3
|
|
|
|
|
11
|
my $method = $self->type; |
158
|
3
|
|
|
|
|
5
|
warn "Essex $self generating $method()\n" if debugging; |
159
|
3
|
|
|
|
|
71
|
return $h->$method( $$self ); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=back |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 LIMITATIONS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright 2002, R. Barrie Slaymaker, Jr., All Rights Reserved |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
You may use this module under the terms of the BSD, Artistic, oir GPL licenses, |
174
|
|
|
|
|
|
|
any version. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 AUTHOR |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Barrie Slaymaker |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |