NAME
SGML::Parser::OpenSP::Tools - Tools to process OpenSP output
DESCRIPTION
Routines to post-process OpenSP event data.
UTILITY FUNCTIONS
- specified_attribute($attribute)
-
specified_attribute returns a true value if the attribute is of type
cdata
ortokenized
and has itsDefaulted
property set tospecified
. For examplesub start_element { my $self = shift; my $elem = shift; my @spec = grep specified_attribute($_), values %{$elem->{Attributes}}; # @spec contains all explicitly specified attributes }
- defaulted_attribute($attribute)
-
defaulted_attribute returns a true value if the attribute is of type
cdata
ortokenized
and has itsDefaulted
property set to something butspecified
. For all attributes, the following always holds true,!defined(attribute_value($_)) or defaulted_attribute($_) or specified_attribute($_)
since only defaulted and specified attributes can have a value.
- value_attribute($attribute)
-
Returns true if the value can have a value, i.e., it is either specified or defaulted.
- attribute_value($attribute)
-
attribute_value returns a textual representation of the value of an attribute as reported to a
start_element
handler orundef
if no value is available. - 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.
It returns a hash reference like
# 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 => 'E', Text => 'ID "a" already defined' }, # only some messages have an aux_message aux_message => { ColumnNumber => 9, LineNumber => 11, Text => 'ID "a" first defined here' }, # iff $p->show_open_elements(1) and there are open elements open_elements => 'html body[1] (p[1])', # 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 => 'example.xhtml', EntityName => 'html', LineNumber => 2 }, ... ],
This would typically be used like
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); # ... }
A more convenient way to access this function is provided by the
SGML::Parser::OpenSP
module which you can use likesub 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 }
- 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 $WHITESPACE package variable, qr/[\x20\x09\x0d\x0a]/ by default. It returns
undef
if there is no data to split.sub pi { my $self = shift; my $proc = shift; my ($target, $data) = split_pi($proc->{Data}); # ... }
AUTHOR / COPYRIGHT / LICENSE
Copyright (c) 2006-2008 Bjoern Hoehrmann <bjoern@hoehrmann.de>.
This module is licensed under the same terms as Perl itself.