.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" 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 .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "ReportParser 3pm" .TH ReportParser 3pm 2025-09-28 "Lire 2.1.1" "LogReport's Lire 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 Lire::ReportParser \- Lire::XMLParser which parses XML reports .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& package MyParser; \& \& use base qw/ Lire::ReportParser /; \& \& sub parse_end { \& return "Finished"; \& } \& \& package main:: \& \& my $parser = new MyParser; \& my $result = eval { $parser\->parsefile( "report.xml" ) }; \& croak "Error parsing report.xml: $@" if $@ \& print $result, "\en"; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This is a \fBLire::XMLParser\fR\|(3pm) subclass which handle XML document adhering to the Lire Report Markup Language format. It\*(Aqs primary purpose is to write custom handlers for the Lire XML Report format. .SH USAGE .IX Header "USAGE" You create an instance of a subclass of Lire::ReportParser and use either one of the \fBparse()\fR or \fBparsefile()\fR methods to process the XML reports. You\*(Aqll probably never use the Lire::ReportParser module directly; you\*(Aqll likely use one subclass which actually does something when processing the document. .ie n .SS "new( %args )" .el .SS "new( \f(CW%args\fP )" .IX Subsection "new( %args )" .Vb 1 \& my $parser = new Lire::ReportParser::ReportBuilder(); .Ve .PP The \fBnew()\fR method takes parameters in the form of \*(Aqkey\*(Aq => value pairs. The available parameters are specific to each processor. There are no generic parameters. .SH "WRITING AN XML REPORT PROCESSOR" .IX Header "WRITING AN XML REPORT PROCESSOR" Using Lire::ReportParser, one can write an XML report processor. .PP The programming model is similar to the expat event\-based interface or the well\-known SAX model. The principal difference with those models is that this module offers hooks specifically tailored for Lire\*(Aqs XML reports. For example, instead of having one generic element\-start event, you have methods for each specific type of element, making it easy to hook on only the elements you\*(Aqre interested in. It also offers some functions that make it easy to determine the context (always a difficulty in event\-based programming). .PP If you are uncomfortable with that kind of programming, there is also an object\-oriented API available to the XML reports. That API is more similar to DOM type of programming. Its principal drawback is that its less performant since it has to parse the whole XML document in memory to build an object representation. But if you need to "navigate" the document, it\*(Aqs a lot better than the event\-based API. .PP The main way of using that API to write a custom XML report handler is by subclassing the Lire::ReportParser module and overriding the functions related to the elements you are interested in. .PP There are 3 categories of methods you can override. .IP "Customization Methods" 4 .IX Item "Customization Methods" Those are methods that customize the way the Lire::ReportParser will operate. The most important one is the \fBnew()\fR "constructor". .IP "Generic element methods" 4 .IX Item "Generic element methods" Those are methods that are invoked on each element before the more specific or higher ones and can be used to hook before the other events are synthesized. .SH "HIGH\-LEVEL EVENT METHODS" .IX Header "HIGH-LEVEL EVENT METHODS" For each element defined, an \fIelement_name\fR\fB_start()\fR and an \&\fIelement_name\fR\fB_end()\fR method are invoked. For elements that contains character data, an \fIelement_name\fR\fB_char()\fR method will also be invoked altough, you probably want to hook onto the easier handle_\fIelement_name\fR() methods in these cases. .PP When you override any of those mehod (except the handle_\fIelement_name\fR() one), you \fBmust\fR invoke the parent method also: .PP .Vb 2 \& sub subreport_start { \& my ( $self, $name, $attr ) = @_; \& \& $self\->SUPER::subreport_start( $name, $attr ); \& \& # Processor specific handling. \& } .Ve .ie n .SS "report_start( $name, $attr )" .el .SS "report_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "report_start( $name, $attr )" Called when the report element start tag is encountered. .PP The only defined attribute is \f(CW\*(C`version\*(C'\fR. The current version is 2.0, but older 1.0 report can still be parsed. .ie n .SS "report_end( $name )" .el .SS "report_end( \f(CW$name\fP )" .IX Subsection "report_end( $name )" Called when the report element end tag is encountered. .ie n .SS "handle_title( $title )" .el .SS "handle_title( \f(CW$title\fP )" .IX Subsection "handle_title( $title )" Method invoked after the \f(CW\*(C`title\*(C'\fR element was processed. The \f(CW$title\fR parameter contains the content of the element. This can be a report\*(Aqs, subreport\*(Aqs or section\*(Aqs title. You\*(Aqll need to use the \&\fBin_element()\fR method to determine the context. .ie n .SS "handle_description( $docbook_desc )" .el .SS "handle_description( \f(CW$docbook_desc\fP )" .IX Subsection "handle_description( $docbook_desc )" Unless the description_start and description_end events are overriden the content of the description will be collected and will be available in the \fBhandle_description()\fR method. .ie n .SS "handle_date( $date, $date_epoch )" .el .SS "handle_date( \f(CW$date\fP, \f(CW$date_epoch\fP )" .IX Subsection "handle_date( $date, $date_epoch )" Called after the \f(CW\*(C`date\*(C'\fR element was parsed. The formatted date is available in the \f(CW$date\fR parameter, the date in number of seconds since the epoch is available in the \f(CW$date_epoch\fR parameter. .PP This can be the report\*(Aqs or a subreport\*(Aqs date, you\*(Aqll need to use the \&\fBin_element()\fR method to determine the appropriate context. .ie n .SS "handle_timespan( $timespan, $epoch_start, $epoch_end, $period )" .el .SS "handle_timespan( \f(CW$timespan\fP, \f(CW$epoch_start\fP, \f(CW$epoch_end\fP, \f(CW$period\fP )" .IX Subsection "handle_timespan( $timespan, $epoch_start, $epoch_end, $period )" Called after the \f(CW\*(C`timespan\*(C'\fR element was parsed. The formatted timespan is available in the \f(CW$timespan\fR parameter, starting and ending dates of the timespan are available as number of seconds since the epoch in the \f(CW$epoch_start\fR and \f(CW$epoch_end\fR parameters. The \f(CW$period\fR parameter contians the timespan\*(Aqs period attribute. .PP This can be the timespan of the report or the subreport, you\*(Aqll need to use the \fBin_element()\fR method to determine the appropriate context. .ie n .SS "section_start( $name, $attr )" .el .SS "section_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "section_start( $name, $attr )" Called when the opening tag of a \f(CW\*(C`section\*(C'\fR element is encountered. .ie n .SS "section_end( $name )" .el .SS "section_end( \f(CW$name\fP )" .IX Subsection "section_end( $name )" Called when the closing tag of a \f(CW\*(C`section\*(C'\fR element is encountered. .ie n .SS "missing_subreport_start( $name, $attr )" .el .SS "missing_subreport_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "missing_subreport_start( $name, $attr )" Called when the opening tag of a \f(CW\*(C`missing\-subreport\*(C'\fR element is encountered. The \f(CW\*(C`superservice\*(C'\fR attribute contains the superservice\*(Aqs of the subreport, the \f(CW\*(C`type\*(C'\fR attribute contains the report specification ID and the \f(CW\*(C`reason\*(C'\fR attribute will contains the reason why the subreport is missing. .ie n .SS "missing_subreport_end( $name )" .el .SS "missing_subreport_end( \f(CW$name\fP )" .IX Subsection "missing_subreport_end( $name )" Called when the closing tag of a \f(CW\*(C`missing\-subreport\*(C'\fR element is encountered. .ie n .SS "subreport_start( $name, $attr )" .el .SS "subreport_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "subreport_start( $name, $attr )" Called when the opening tag of the \f(CW\*(C`subreport\*(C'\fR element is encountered. The \f(CW\*(C`superservice\*(C'\fR attribute contains the subreport\*(Aqs superservice and the \f(CW\*(C`type\*(C'\fR attribute contains the ID of the report specification that was used to generate that subreport. .ie n .SS "subreport_end( $name )" .el .SS "subreport_end( \f(CW$name\fP )" .IX Subsection "subreport_end( $name )" Called when the \f(CW\*(C`subreport\*(C'\fR\*(Aqs closing tag is encountered. .ie n .SS "table_start( $name, $attr )" .el .SS "table_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "table_start( $name, $attr )" Called when the opening tag of the \f(CW\*(C`table\*(C'\fR element is encountered. The \f(CW\*(C`show\*(C'\fR attribute contains the maximum number of entries that should be displayed (there may more entries than this number). .ie n .SS "table_end( $name )" .el .SS "table_end( \f(CW$name\fP )" .IX Subsection "table_end( $name )" Called when the \f(CW\*(C`table\*(C'\fR\*(Aqs closing tag is encountered. .ie n .SS "table_info_start( $name, $attr )" .el .SS "table_info_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "table_info_start( $name, $attr )" Called when the \f(CW\*(C`table\-info\*(C'\fR\*(Aqs closing tag is encountered. .PP There should be no reason for subclasses to override this method. The Lire::ReportParser takes care of parsing the \f(CW\*(C`table\-info\*(C'\fR content and offers that information through a Lire::Report::TableInfo object which is accessible through the \fBcurrent_table_info()\fR method. .ie n .SS "table_info_end( $name )" .el .SS "table_info_end( \f(CW$name\fP )" .IX Subsection "table_info_end( $name )" Called when the \f(CW\*(C`table\-info\*(C'\fR\*(Aqs closing tag is encountered. See \&\fBtable_info_start()\fR documentation for important comments. .ie n .SS "group_info_start( $name, $attr )" .el .SS "group_info_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "group_info_start( $name, $attr )" Called when the \f(CW\*(C`group\-info\*(C'\fR\*(Aqs opening tag is encountered. See \&\fBtable_info_start()\fR documentation for important comments. .ie n .SS "group_info_end( $name )" .el .SS "group_info_end( \f(CW$name\fP )" .IX Subsection "group_info_end( $name )" Called when the \f(CW\*(C`group\-info\*(C'\fR\*(Aqs closing tag is encountered. See \&\fBtable_info_start()\fR documentation for important comments. .ie n .SS "column_info_start( $name, $attr )" .el .SS "column_info_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "column_info_start( $name, $attr )" Called when the \f(CW\*(C`column\-info\*(C'\fR\*(Aqs opening tag is encountered. See \&\fBtable_info_start()\fR documentation for important comments. .ie n .SS "column_info_end( $name )" .el .SS "column_info_end( \f(CW$name\fP )" .IX Subsection "column_info_end( $name )" Called when the \f(CW\*(C`column\-info\*(C'\fR\*(Aqs closing tag is encountered. See \&\fBtable_info_start()\fR documentation for important comments. .ie n .SS "group_summary_start( $name, $attr )" .el .SS "group_summary_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "group_summary_start( $name, $attr )" Called when the \f(CW\*(C`group\-summary\*(C'\fR\*(Aqs opening tag is encountered. .ie n .SS "group_summary_end( $name )" .el .SS "group_summary_end( \f(CW$name\fP )" .IX Subsection "group_summary_end( $name )" Called when the \f(CW\*(C`group\-summary\*(C'\fR\*(Aqs closing tag is encountered. .ie n .SS "group_start( $name, $attr )" .el .SS "group_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "group_start( $name, $attr )" Called when the opening tag of the \f(CW\*(C`group\*(C'\fR element is encountered. \&\f(CW\*(C`group\*(C'\fR elements introduce a kind of nested table. The \f(CW\*(C`show\*(C'\fR attribute contains the maximum number of entries that should be displayed, altough more entries may be present in the report. .ie n .SS "group_end( $name )" .el .SS "group_end( \f(CW$name\fP )" .IX Subsection "group_end( $name )" Called when the \f(CW\*(C`group\*(C'\fR\*(Aqs closing tag is encountered. .ie n .SS "entry_start( $name, $attr )" .el .SS "entry_start( \f(CW$name\fP, \f(CW$attr\fP )" .IX Subsection "entry_start( $name, $attr )" Called when the opening tag of an \f(CW\*(C`entry\*(C'\fR element is encountered. .ie n .SS "entry_end( $name )" .el .SS "entry_end( \f(CW$name\fP )" .IX Subsection "entry_end( $name )" Called when the \f(CW\*(C`entry\*(C'\fR\*(Aqs closing tag is encountered. .ie n .SS "handle_name( $name_rec )" .el .SS "handle_name( \f(CW$name_rec\fP )" .IX Subsection "handle_name( $name_rec )" Called after a \f(CW\*(C`name\*(C'\fR element was parsed. The \f(CW$name_rec\fR parameter is an hash reference which contains the different values of the name datum. Keys that are defined in this hash: .IP content 4 .IX Item "content" That\*(Aqs the actual content of the name element. This contains the name in a format suitable for display. .IP value 4 .IX Item "value" This contains the unformatted value of the name. For example, when the name is a time string, this attribute will contains the time in seconds since epoch. .IP range 4 .IX Item "range" For some names, the actual content express a range (time, size, etc.). This attribute contains the length of the range. .IP col_info 4 .IX Item "col_info" The Lire::ColumnInfo object describing the column in which this name appears. .ie n .SS "handle_value( $value_rec )" .el .SS "handle_value( \f(CW$value_rec\fP )" .IX Subsection "handle_value( $value_rec )" Called after a \f(CW\*(C`value\*(C'\fR element was parsed. The \f(CW$value_rec\fR parameter is an hash reference which contains the different values of the value datum. Keys that are defined in this hash: .IP content 4 .IX Item "content" That\*(Aqs the actual content of the value element. This contains the value in a format suitable for display. .IP value 4 .IX Item "value" This contains the unformatted value. For example, when bytes are displayed using "1M" or "1.1G", this will contains the value in bytes. .IP total 4 .IX Item "total" This is used by values that represent an average. It contains the total which makes up the average. .IP n 4 .IX Item "n" This is used by values that represent an average. It contains the total which was used in the division to compute the average. .IP col_info 4 .IX Item "col_info" The Lire::ColumnInfo object describing the column in which this name appears. .ie n .SS "handle_summary_value( $value_rec )" .el .SS "handle_summary_value( \f(CW$value_rec\fP )" .IX Subsection "handle_summary_value( $value_rec )" Called after a \f(CW\*(C`value\*(C'\fR element located in the group\-summary element was parsed. The \f(CW$value_rec\fR parameter is identical than in the \&\fBhandle_value()\fR method. .ie n .SS "handle_chart_configs( $configs )" .el .SS "handle_chart_configs( \f(CW$configs\fP )" .IX Subsection "handle_chart_configs( $configs )" If the Subreport contained chart configurations, an array reference of Lire::Report::ChartConfig objects will be passed to this event handler. .SH "CONTEXT METHODS" .IX Header "CONTEXT METHODS" Finally, here a bunch of additional methods that can be used to query some context information when processing elements. .SS "current_subreport_count( )" .IX Subsection "current_subreport_count( )" Returns the number of subreport that are present to date in the report. That number is equals to the number of processed \f(CW\*(C`subreport\*(C'\fR elements, i.e. the current subreport isn\*(Aqt counted untill the closing tag was processed. .SS "current_section_subreport_count( )" .IX Subsection "current_section_subreport_count( )" Returns the number of subreport that are present to date in the section. That number is equals to the number of processed \f(CW\*(C`subreport\*(C'\fR elements, i.e. the current subreport isn\*(Aqt counted untill the closing tag was processed. .SS "current_date( )" .IX Subsection "current_date( )" Returns the content of the \f(CW\*(C`date\*(C'\fR element that applies to the current element. This will either be the current subreport\*(Aqs date or the default one taken from the \f(CW\*(C`report\*(C'\fR element. .PP The date is returned as an hash reference which will contain the formatted date in the \f(CW\*(C`date\*(C'\fR key and the date in seconds since epoch in the \f(CW\*(C`time\*(C'\fR key. .SS "current_timespan( )" .IX Subsection "current_timespan( )" Returns the content of the \f(CW\*(C`timespan\*(C'\fR element that applies to the current element. This will either be the current subreport\*(Aqs date or the default one taken from the \f(CW\*(C`report\*(C'\fR element. .PP The timespan is returned as an hash reference which will contain the formatted timespan in the \f(CW\*(C`timespan\*(C'\fR key. The starting and ending date of the timespan are available as seconds since epoch in the \&\f(CW\*(C`start\*(C'\fR and \f(CW\*(C`end\*(C'\fR keys. The \f(CW\*(C`period\*(C'\fR key contains the report\*(Aqs timespan. .SS "current_superservice( )" .IX Subsection "current_superservice( )" Useful in \f(CW\*(C`subreport\*(C'\fR context, it returns the superservice\*(Aqs of the current subreport. .SS "current_type( )" .IX Subsection "current_type( )" Useful in \f(CW\*(C`subreport\*(C'\fR context, it returns the ID of the report specification that was used to generate the current subreport. .SS \fBcurrent_table_info()\fP .IX Subsection "current_table_info()" Useful when processing \f(CW\*(C`group\*(C'\fR and \f(CW\*(C`entry\*(C'\fR, this returns a Lire::Report;:TableInfo object which describes the layout of the current table. .SS "current_group_entry_show( )" .IX Subsection "current_group_entry_show( )" Useful in \f(CW\*(C`table\*(C'\fR and \f(CW\*(C`group\*(C'\fR context, it returns the maximum number of entries that should be displayed. .SS "show_current_entry( )" .IX Subsection "show_current_entry( )" Useful in \f(CW\*(C`entry\*(C'\fR context , this can be used to test whether or not the current \f(CW\*(C`entry\*(C'\fR should be displayed based on the current entry index and the parent\*(Aqs \f(CW\*(C`show\*(C'\fR attribute. .SS "current_table_entry_count( )" .IX Subsection "current_table_entry_count( )" Useful in \f(CW\*(C`table\*(C'\fR context, it returns the number of entries that were processed so far. This only reports the entries in the \f(CW\*(C`table\*(C'\fR element, not counting the one in the nested \f(CW\*(C`group\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" .Vb 8 \& Lire::Report(3pm), Lire::XMLParser(3pm) \& Lire::ReportParser::AsciiDocBookFormatter(3pm), \& Lire::ReportParser::AsciiWriter(3pm), \& Lire::ReportParser::HTMLDocBookFormatter(3pm), \& Lire::ReportParser::HTMLWriter(3pm), \& Lire::ReportParser::ReportBuilder(3pm), \& Lire::ReportParser::ExcelWriter(3pm), \& Lire::Report::TableInfo(3pm) .Ve .SH AUTHOR .IX Header "AUTHOR" .Vb 1 \& Francis J. Lacoste .Ve .SH VERSION .IX Header "VERSION" \&\f(CW$Id:\fR ReportParser.pm,v 1.52 2006/07/23 13:16:29 vanbaal Exp $ .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (C) 2001\-2004 Stichting LogReport Foundation LogReport@LogReport.org .PP This file is part of Lire. .PP Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. .PP You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html.