| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::CAP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23895
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
408
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# defined exeptions |
|
8
|
|
|
|
|
|
|
use Exception::Class ( |
|
9
|
|
|
|
|
|
|
"XML::CAP::Exception", |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
"XML::CAP::TracedException" => { |
|
12
|
|
|
|
|
|
|
isa => "XML::CAP::Exception", |
|
13
|
|
|
|
|
|
|
}, |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
"XML::CAP::Exception::AbstractMethod" => { |
|
16
|
|
|
|
|
|
|
isa => "XML::CAP::Exception", |
|
17
|
|
|
|
|
|
|
alias => "throw_abstract_method", |
|
18
|
|
|
|
|
|
|
description => "abstract method must be overridden by a subclass", |
|
19
|
|
|
|
|
|
|
}, |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# define exports |
|
23
|
|
|
|
|
|
|
use base "Exporter"; |
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( &eval_wrapper ); |
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = qw( &eval_wrapper ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# package globals |
|
28
|
|
|
|
|
|
|
our $DefaultVersion = '1.1'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
XML::CAP - parse or generate the XML Common Alerting Protocol (CAP) |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 VERSION |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Version 0.02 |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
XML::CAP parses and generates XML Common Alerting Protocol (CAP). |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
More information about CAP can be found at L |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Each XML CAP structure has an "alert" section. Each alert may contain |
|
50
|
|
|
|
|
|
|
zero (usually one) or more "info" sections. Each info section may contain |
|
51
|
|
|
|
|
|
|
zero or more "resource" and/or "area" sections. Each area section may |
|
52
|
|
|
|
|
|
|
contain zero or more "geocode" sections. All of these sections are |
|
53
|
|
|
|
|
|
|
represented by subclasses of XML::CAP. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
XML::CAP uses XML::LibXML. There are accessor functions for every element. |
|
56
|
|
|
|
|
|
|
But using the elem() method, there is also direct access to the corresponding |
|
57
|
|
|
|
|
|
|
LibXML node. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Code sample: |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use XML::CAP; |
|
62
|
|
|
|
|
|
|
use XML::CAP::Parser; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $parser = XML::CAP::Parser->new(); |
|
65
|
|
|
|
|
|
|
$parser->parse_file( "cap-file.xml" ); |
|
66
|
|
|
|
|
|
|
my $alert; |
|
67
|
|
|
|
|
|
|
eval_wrapper ( sub { $alert = $parser->alert }); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
@alert_nodes = $alert->elem->childnodes; # access to XML::libXML data |
|
70
|
|
|
|
|
|
|
$identifier = $alert->identifier; |
|
71
|
|
|
|
|
|
|
$sender = $alert->sender; |
|
72
|
|
|
|
|
|
|
$sent = $alert->sent; |
|
73
|
|
|
|
|
|
|
$status = $alert->status; |
|
74
|
|
|
|
|
|
|
$msgType = $alert->msgType; |
|
75
|
|
|
|
|
|
|
$source = $alert->source; |
|
76
|
|
|
|
|
|
|
$scope = $alert->scope; |
|
77
|
|
|
|
|
|
|
$restriction = $alert->restriction; |
|
78
|
|
|
|
|
|
|
$addresses = $alert->addresses; |
|
79
|
|
|
|
|
|
|
$code = $alert->code; |
|
80
|
|
|
|
|
|
|
$note = $alert->note; |
|
81
|
|
|
|
|
|
|
$references = $alert->references; |
|
82
|
|
|
|
|
|
|
$incidents = $alert->incidents; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my @infos = $alert->infos; |
|
85
|
|
|
|
|
|
|
@info_nodes = $infos[0]->elem->childnodes; # access LibXML data |
|
86
|
|
|
|
|
|
|
my $info = $infos[0]; |
|
87
|
|
|
|
|
|
|
$language = $info->language; |
|
88
|
|
|
|
|
|
|
$category = $info->category; |
|
89
|
|
|
|
|
|
|
$event = $info->event; |
|
90
|
|
|
|
|
|
|
$responseType = $info->responseType; |
|
91
|
|
|
|
|
|
|
$urgency = $info->urgency; |
|
92
|
|
|
|
|
|
|
$severity = $info->severity; |
|
93
|
|
|
|
|
|
|
$certainty = $info->certainty; |
|
94
|
|
|
|
|
|
|
$audience = $info->audience; |
|
95
|
|
|
|
|
|
|
$eventCode = $info->eventCode; |
|
96
|
|
|
|
|
|
|
$effective = $info->effective; |
|
97
|
|
|
|
|
|
|
$onset = $info->onset; |
|
98
|
|
|
|
|
|
|
$expires = $info->expires; |
|
99
|
|
|
|
|
|
|
$senderName = $info->senderName; |
|
100
|
|
|
|
|
|
|
$headline = $info->headline; |
|
101
|
|
|
|
|
|
|
$description = $info->description; |
|
102
|
|
|
|
|
|
|
$instruction = $info->instruction; |
|
103
|
|
|
|
|
|
|
$web = $info->web; |
|
104
|
|
|
|
|
|
|
$contact = $info->contact; |
|
105
|
|
|
|
|
|
|
$parameter = $info->parameter; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my @resources = $info->resources; |
|
108
|
|
|
|
|
|
|
@resource_nodes = $resources[0]->elem->childnodes; # access LibXML data |
|
109
|
|
|
|
|
|
|
my $resource = $resources[0]; |
|
110
|
|
|
|
|
|
|
$resourceDesc = $resource->resourceDesc; |
|
111
|
|
|
|
|
|
|
$mimeType = $resource->mimeType; |
|
112
|
|
|
|
|
|
|
$size = $resource->size; |
|
113
|
|
|
|
|
|
|
$uri = $resource->uri; |
|
114
|
|
|
|
|
|
|
$derefUri = $resource->derefUri; |
|
115
|
|
|
|
|
|
|
$digest = $resource->digest; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my @areas = $info->areas; |
|
118
|
|
|
|
|
|
|
@area_nodes = $areas[0]->elem->childnodes; # access LibXML data |
|
119
|
|
|
|
|
|
|
my $area = $areas[0]; |
|
120
|
|
|
|
|
|
|
$areaDesc = $area->areaDesc; |
|
121
|
|
|
|
|
|
|
$polygon = $area->polygon; |
|
122
|
|
|
|
|
|
|
$circle = $area->circle; |
|
123
|
|
|
|
|
|
|
$altitude = $area->altitude; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my @geocodes = $area->geocodes; |
|
126
|
|
|
|
|
|
|
@geocode_nodes = $geocodes[0]->elem->childnodes; # access LibXML data |
|
127
|
|
|
|
|
|
|
my $geocode = $geocodes[0]; |
|
128
|
|
|
|
|
|
|
$valueName = $geocode->valueName; |
|
129
|
|
|
|
|
|
|
$value = $geocode->value; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 new |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub new { |
|
139
|
|
|
|
|
|
|
my $class = shift; |
|
140
|
|
|
|
|
|
|
my $self = {}; |
|
141
|
|
|
|
|
|
|
bless $self, $class; |
|
142
|
|
|
|
|
|
|
$self->initialize( @_ ); |
|
143
|
|
|
|
|
|
|
return $self; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 initialize |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub initialize { |
|
152
|
|
|
|
|
|
|
throw_abstract_method( "initialize() must be provided by subclass" ); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 eval_wrapper ( $code, $throw_func, [ name => value, ...] ) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# eval_wrapper - catch exceptions from XML::LibXML, XML::CAP or others |
|
160
|
|
|
|
|
|
|
sub eval_wrapper |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
|
|
|
|
|
|
my $code = shift; |
|
163
|
|
|
|
|
|
|
my $throw_func = shift; |
|
164
|
|
|
|
|
|
|
my %params = @_; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# run the code in an eval so we can catch exceptions |
|
167
|
|
|
|
|
|
|
my $result = eval { &$code; }; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# process any exception that we may have gotten |
|
170
|
|
|
|
|
|
|
if ( $@ ) { |
|
171
|
|
|
|
|
|
|
my $ex = $@; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# determine if there's an error message available |
|
174
|
|
|
|
|
|
|
my $msg; |
|
175
|
|
|
|
|
|
|
if ( ref $ex ) { |
|
176
|
|
|
|
|
|
|
if ( my $ex_cap = Exception::Class->caught( |
|
177
|
|
|
|
|
|
|
"XML::CAP::Exception")) |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
|
|
|
|
|
|
warn (ref $ex_cap).": ".$ex_cap->error."\n"; |
|
180
|
|
|
|
|
|
|
if ( $ex_cap->isa( "XML::CAP::TracedException" )) { |
|
181
|
|
|
|
|
|
|
warn $ex_cap->trace->as_string, "\n"; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
if ( $params{no_rethrow} ) { |
|
185
|
|
|
|
|
|
|
# it's our own exception so rethrow it |
|
186
|
|
|
|
|
|
|
# to maintain details |
|
187
|
|
|
|
|
|
|
$ex_cap->rethrow |
|
188
|
|
|
|
|
|
|
} else { |
|
189
|
|
|
|
|
|
|
$msg = $ex_cap->error; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
if ( $ex->can("stringify")) { |
|
193
|
|
|
|
|
|
|
# Error.pm, possibly others |
|
194
|
|
|
|
|
|
|
$msg = $ex->stringify; |
|
195
|
|
|
|
|
|
|
} elsif ( $ex->can("as_string")) { |
|
196
|
|
|
|
|
|
|
# generic - should work for many classes |
|
197
|
|
|
|
|
|
|
$msg = $ex->as_string; |
|
198
|
|
|
|
|
|
|
} else { |
|
199
|
|
|
|
|
|
|
$msg = "unknown exception of type ".(ref $ex); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
} else { |
|
202
|
|
|
|
|
|
|
$msg = $@; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# use the captured error message to throw our own exception |
|
206
|
|
|
|
|
|
|
# or print error messages before exiting |
|
207
|
|
|
|
|
|
|
&$throw_func ( $msg ); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# success |
|
211
|
|
|
|
|
|
|
return $result; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Ian Kluft, C<< >> |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 BUGS |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
221
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
222
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SUPPORT |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
perldoc XML::CAP |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
You can also look for information at: |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=over 4 |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
L |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * Search CPAN |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=back |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
The initial version was derived from XML::Atom by Benjamin Trott and |
|
260
|
|
|
|
|
|
|
Tatsuhiko Miyagawa. |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Copyright 2009 Ian Kluft, all rights reserved. |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
268
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; # End of XML::CAP |