.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "SGML::Parser::OpenSP::Tools 3pm" .TH SGML::Parser::OpenSP::Tools 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SGML::Parser::OpenSP::Tools \- Tools to process OpenSP output .SH DESCRIPTION .IX Header "DESCRIPTION" Routines to post-process OpenSP event data. .SH "UTILITY FUNCTIONS" .IX Header "UTILITY FUNCTIONS" .IP specified_attribute($attribute) 4 .IX Item "specified_attribute($attribute)" specified_attribute returns a true value if the attribute is of type \f(CW\*(C`cdata\*(C'\fR or \f(CW\*(C`tokenized\*(C'\fR and has its \f(CW\*(C`Defaulted\*(C'\fR property set to \f(CW\*(C`specified\*(C'\fR. For example .Sp .Vb 6 \& sub start_element \& { \& my $self = shift; \& my $elem = shift; \& my @spec = grep specified_attribute($_), \& values %{$elem\->{Attributes}}; \& \& # @spec contains all explicitly specified attributes \& } .Ve .IP defaulted_attribute($attribute) 4 .IX Item "defaulted_attribute($attribute)" defaulted_attribute returns a true value if the attribute is of type \f(CW\*(C`cdata\*(C'\fR or \f(CW\*(C`tokenized\*(C'\fR and has its \f(CW\*(C`Defaulted\*(C'\fR property set to something but \f(CW\*(C`specified\*(C'\fR. For all attributes, the following always holds true, .Sp .Vb 3 \& !defined(attribute_value($_)) or \& defaulted_attribute($_) or \& specified_attribute($_) .Ve .Sp since only defaulted and specified attributes can have a value. .IP value_attribute($attribute) 4 .IX Item "value_attribute($attribute)" Returns true if the value can have a value, i.e., it is either specified or defaulted. .IP attribute_value($attribute) 4 .IX Item "attribute_value($attribute)" attribute_value returns a textual representation of the value of an attribute as reported to a \f(CW\*(C`start_element\*(C'\fR handler or \&\f(CW\*(C`undef\*(C'\fR if no value is available. .ie n .IP "split_message($message, $filename, $open_ent, $error_num, $open_elem)" 4 .el .IP "split_message($message, \f(CW$filename\fR, \f(CW$open_ent\fR, \f(CW$error_num\fR, \f(CW$open_elem\fR)" 4 .IX Item "split_message($message, $filename, $open_ent, $error_num, $open_elem)" split_message splits an OpenSP error message into its components, the error or warning message, an optional auxiliary message that provides additional information about the error, like the first occurence of an ID in case of duplicate IDs in a document, each accompanied by line and column numbers relevant to the message, and depending on the parser configuration the open entities for the message, the error number of the message and a list of the current open elements. .Sp It returns a hash reference like .Sp .Vb 10 \& # this is always present \& primary_message => \& { \& Number => 141, # only if $p\->show_error_numbers(1) \& Module => 554521624, # only if $p\->show_error_numbers(1) \& ColumnNumber => 9, \& LineNumber => 12, \& Severity => \*(AqE\*(Aq, \& Text => \*(AqID "a" already defined\*(Aq \& }, \& \& # only some messages have an aux_message \& aux_message => \& { \& ColumnNumber => 9, \& LineNumber => 11, \& Text => \*(AqID "a" first defined here\*(Aq \& }, \& \& # iff $p\->show_open_elements(1) and there are open elements \& open_elements => \*(Aqhtml body[1] (p[1])\*(Aq, \& \& # iff $p\->show_open_entities(1) and there are open entities \& # other than the document, but the document will be reported \& # if the error is in some other entity \& open_entities => [ \& { \& ColumnNumber => 55, \& FileName => \*(Aqexample.xhtml\*(Aq, \& EntityName => \*(Aqhtml\*(Aq, \& LineNumber => 2 \& }, ... ], .Ve .Sp This would typically be used like .Sp .Vb 5 \& sub error \& { \& my $self = shift; \& my $erro = shift; \& my $mess = $erro\->{Message}; \& \& # parser is the SGML::Parser::OpenSP \& # object stored in the handler object \& my $loca = $self\->{parser}\->get_location; \& my $name = $loca\->{FileName}; \& \& my $splt = split_message($mess, $name, \& $self\->{parser}\->show_open_entities, \& $self\->{parser}\->show_error_numbers, \& $self\->{parser}\->show_open_elements); \& \& # ... \& } .Ve .Sp A more convenient way to access this function is provided by the \&\f(CW\*(C`SGML::Parser::OpenSP\*(C'\fR module which you can use like .Sp .Vb 4 \& sub error \& { \& my $self = shift; \& my $erro = shift; \& \& my $mess = $self\->{parser}\->split_message($erro); \& \& # relevant data is now $mess and $erro\->{Severity} \& # of which the latter provides more detailed information \& # than $mess\->{primary_message}\->{Severity}, see the \& # SGML::Parser::OpenSP documentation for details \& } .Ve .IP split_pi($data) 4 .IX Item "split_pi($data)" split_pi splits the data of a processing instructions at the first white space character into two components where white space character is defined in the \f(CW$WHITESPACE\fR package variable, qr/[\ex20\ex09\ex0d\ex0a]/ by default. It returns \f(CW\*(C`undef\*(C'\fR if there is no data to split. .Sp .Vb 4 \& sub pi \& { \& my $self = shift; \& my $proc = shift; \& \& my ($target, $data) = split_pi($proc\->{Data}); \& \& # ... \& } .Ve .SH "AUTHOR / COPYRIGHT / LICENSE" .IX Header "AUTHOR / COPYRIGHT / LICENSE" .Vb 2 \& Copyright (c) 2006\-2008 Bjoern Hoehrmann . \& This module is licensed under the same terms as Perl itself. .Ve