1SGML::Parser::OpenSP::TUosoelrs(C3o)ntributed Perl DocumSeGnMtLa:t:iPoanrser::OpenSP::Tools(3)
2
3
4

NAME

6       SGML::Parser::OpenSP::Tools - Tools to process OpenSP output
7

DESCRIPTION

9       Routines to post-process OpenSP event data.
10

UTILITY FUNCTIONS

12       specified_attribute($attribute)
13           specified_attribute returns a true value if the attribute is of
14           type "cdata" or "tokenized" and has its "Defaulted" property set to
15           "specified". For example
16
17             sub start_element
18             {
19               my $self = shift;
20               my $elem = shift;
21               my @spec = grep specified_attribute($_),
22                               values %{$elem->{Attributes}};
23
24               # @spec contains all explicitly specified attributes
25             }
26
27       defaulted_attribute($attribute)
28           defaulted_attribute returns a true value if the attribute is of
29           type "cdata" or "tokenized" and has its "Defaulted" property set to
30           something but "specified". For all attributes, the following always
31           holds true,
32
33             !defined(attribute_value($_)) or
34             defaulted_attribute($_) or
35             specified_attribute($_)
36
37           since only defaulted and specified attributes can have a value.
38
39       value_attribute($attribute)
40           Returns true if the value can have a value, i.e., it is either
41           specified or defaulted.
42
43       attribute_value($attribute)
44           attribute_value returns a textual representation of the value of an
45           attribute as reported to a "start_element" handler or "undef" if no
46           value is available.
47
48       split_message($message, $filename, $open_ent, $error_num, $open_elem)
49           split_message splits an OpenSP error message into its components,
50           the error or warning message, an optional auxiliary message that
51           provides additional information about the error, like the first
52           occurence of an ID in case of duplicate IDs in a document, each
53           accompanied by line and column numbers relevant to the message, and
54           depending on the parser configuration the open entities for the
55           message, the error number of the message and a list of the current
56           open elements.
57
58           It returns a hash reference like
59
60             # this is always present
61             primary_message =>
62             {
63               Number       => 141,       # only if $p->show_error_numbers(1)
64               Module       => 554521624, # only if $p->show_error_numbers(1)
65               ColumnNumber => 9,
66               LineNumber   => 12,
67               Severity     => 'E',
68               Text         => 'ID "a" already defined'
69             },
70
71             # only some messages have an aux_message
72             aux_message =>
73             {
74               ColumnNumber => 9,
75               LineNumber   => 11,
76               Text         => 'ID "a" first defined here'
77             },
78
79             # iff $p->show_open_elements(1) and there are open elements
80             open_elements => 'html body[1] (p[1])',
81
82             # iff $p->show_open_entities(1) and there are open entities
83             # other than the document, but the document will be reported
84             # if the error is in some other entity
85             open_entities => [
86             {
87               ColumnNumber => 55,
88               FileName     => 'example.xhtml',
89               EntityName   => 'html',
90               LineNumber   => 2
91             }, ... ],
92
93           This would typically be used like
94
95             sub error
96             {
97               my $self = shift;
98               my $erro = shift;
99               my $mess = $erro->{Message};
100
101               # parser is the SGML::Parser::OpenSP
102               # object stored in the handler object
103               my $loca = $self->{parser}->get_location;
104               my $name = $loca->{FileName};
105
106               my $splt = split_message($mess, $name,
107                                        $self->{parser}->show_open_entities,
108                                        $self->{parser}->show_error_numbers,
109                                        $self->{parser}->show_open_elements);
110
111               # ...
112             }
113
114           A more convenient way to access this function is provided by the
115           "SGML::Parser::OpenSP" module which you can use like
116
117             sub error
118             {
119               my $self = shift;
120               my $erro = shift;
121
122               my $mess = $self->{parser}->split_message($erro);
123
124               # relevant data is now $mess and $erro->{Severity}
125               # of which the latter provides more detailed information
126               # than $mess->{primary_message}->{Severity}, see the
127               # SGML::Parser::OpenSP documentation for details
128             }
129
130       split_pi($data)
131           split_pi splits the data of a processing instructions at the first
132           white space character into two components where white space
133           character is defined in the $WHITESPACE package variable,
134           qr/[\x20\x09\x0d\x0a]/ by default. It returns "undef" if there is
135           no data to split.
136
137             sub pi
138             {
139               my $self = shift;
140               my $proc = shift;
141
142               my ($target, $data) = split_pi($proc->{Data});
143
144               # ...
145             }
146
148         Copyright (c) 2006-2008 Bjoern Hoehrmann <bjoern@hoehrmann.de>.
149         This module is licensed under the same terms as Perl itself.
150
151
152
153perl v5.32.0                      2020-07-28    SGML::Parser::OpenSP::Tools(3)
Impressum