ReportParser(3pm)
okay bestie, welcome to ReportParser(3pm) β that's Lire::ReportParser, straight from LogReport's Lire Documentation. This is part one, and we are keeping every single detail, no cap. π
πΈ NAME πΈ
Lire::ReportParser β a Lire::XMLParser(3pm) subclass that parses XML reports. Its whole personality is handling XML documents that adhere to the Lire Report Markup Language format.
π¦ SYNOPSIS π¦
Here's the vibe in code:
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, "\n";
β¨ DESCRIPTION β¨
Okay so Lire::ReportParser is a Lire::XMLParser(3pm) subclass, and it handles XML documents that adhere to the Lire Report Markup Language format. Its main purpose is writing custom handlers for the Lire XML Report format. π
π USAGE π
You create an instance of a subclass of Lire::ReportParser, then use either one of the parse() or parsefile() methods to process the XML reports. You'll probably never use the Lire::ReportParser module directly β you'll likely use one subclass that actually does something when processing the document. π«Ά
π new( %args ) π
my $parser = new Lire::ReportParser::ReportBuilder();
The new() method takes parameters in the form of 'key' => value pairs. The available parameters are specific to each processor. There are no generic parameters. Periodt.
π WRITING AN XML REPORT PROCESSOR π
Using Lire::ReportParser, one can write an XML report processor.
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's 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're interested in. It also offers some functions that make it easy to determine the context β always a difficulty in event-based programming. β¨
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 it's 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's a lot better than the event-based API. π¦
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.
There are 3 categories of methods you can override.
π Customization Methods π
Those are methods that customize the way the Lire::ReportParser will operate. The most important one is the new() "constructor".
π 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.
π₯ HIGH-LEVEL EVENT METHODS π₯
For each element defined, an element_name_start() and an element_name_end() method are invoked. For elements that contain character data, an element_name_char() method will also be invoked β although honestly you probably want to hook onto the easier handle_element_name() methods in these cases. π
When you override any of those methods (except the handle_element_name() one), you must invoke the parent method also:
sub subreport_start {
my ( $self, $name, $attr ) = @_;
$self->SUPER::subreport_start( $name, $attr );
# Processor specific handling.
}
report_start( $name, $attr )β called when thereportelement start tag is encountered.
The only defined attribute is "version". The current version is 2.0, but older 1.0 report can still be parsed.
report_end( $name )β called when thereportelement end tag is encountered.handle_title( $title )β method invoked after the"title"element was processed. The$titleparameter contains the content of the element. This can be a report's, subreport's or section's title. You'll need to use thein_element()method to determine the context.handle_description( $docbook_desc )β unless thedescription_startanddescription_endevents are overridden, the content of the description will be collected and will be available in thehandle_description()method.handle_date( $date, $date_epoch )β called after the"date"element was parsed. The formatted date is available in the$dateparameter, and the date in number of seconds since the epoch is available in the$date_epochparameter.
This can be the report's or a subreport's date, so you'll need to use the in_element() method to determine the appropriate context.
handle_timespan( $timespan, $epoch_start, $epoch_end, $period )β called after the"timespan"element was parsed. The formatted timespan is available in the$timespanparameter, starting and ending dates of the timespan are available as number of seconds since the epoch in the$epoch_startand$epoch_endparameters. The$periodparameter contains the timespan'speriodattribute.
This can be the timespan of the report or the subreport, so you'll need to use the in_element() method to determine the appropriate context.
section_start( $name, $attr )β called when the opening tag of a"section"element is encountered.section_end( $name )β called when the closing tag of a"section"element is encountered.missing_subreport_start( $name, $attr )β called when the opening tag of a"missing-subreport"element is encountered. The"superservice"attribute contains the subreport's superservice, the"type"attribute contains the report specification ID, and the"reason"attribute will contain the reason why the subreport is missing.missing_subreport_end( $name )β called when the closing tag of a"missing-subreport"element is encountered.subreport_start( $name, $attr )β called when the opening tag of the"subreport"element is encountered. The"superservice"attribute contains the subreport's superservice and the"type"attribute contains the ID of the report specification that was used to generate that subreport.subreport_end( $name )β called when the"subreport"'s closing tag is encountered.table_start( $name, $attr )β called when the opening tag of the"table"element is encountered. The"show"attribute contains the maximum number of entries that should be displayed (there may be more entries than this number).table_end( $name )β called when the"table"'s closing tag is encountered.table_info_start( $name, $attr )β called when the"table-info"'s closing tag is encountered.
There should be no reason for subclasses to override this method. The Lire::ReportParser takes care of parsing the "table-info" content and offers that information through a Lire::Report::TableInfo object which is accessible through the current_table_info() method.
table_info_end( $name )β called when the"table-info"'s closing tag is encountered. Seetable_info_start()documentation for important comments.group_info_start( $name, $attr )β called when the"group-info"'s opening tag is encountered. Seetable_info_start()documentation for important comments.group_info_end( $name )β called when the"group-info"'s closing tag is encountered. Seetable_info_start()documentation for important comments.column_info_start( $name, $attr )β called when the"column-info"'s opening tag is encountered. Seetable_info_start()documentation for important comments.column_info_end( $name )β called when the"column-info"'s closing tag is encountered. Seetable_info_start()documentation for important comments.group_summary_start( $name, $attr )β called when the"group-summary"'s opening tag is encountered.group_summary_end( $name )β called when the"group-summary"'s closing tag is encountered.group_start( $name, $attr )β called when the opening tag of the"group"element is encountered."group"elements introduce a kind of nested table. The"show"attribute contains the maximum number of entries that should be displayed, although more entries may be present in the report.group_end( $name )β called when the"group"'s closing tag is encountered.entry_start( $name, $attr )β called when the opening tag of an"entry"element is encountered.entry_end( $name )β called when the"entry"'s closing tag is encountered.handle_name( $name_rec )β called after a"name"element was parsed. The$name_recparameter is a hash reference which contains the different values of the name datum. Keys that are defined in this hash:contentβ that's the actual content of the name element. This contains the name in a format suitable for display.valueβ this contains the unformatted value of the name. For example, when the name is a time string, this attribute will contain the time in seconds since epoch.rangeβ for some names, the actual content expresses a range (time, size, etc.). This attribute contains the length of the range.col_infoβ theLire::ColumnInfoobject describing the column in which this name appears.
handle_value( $value_rec )β called after a"value"element was parsed. The$value_recparameter is a hash reference which contains the different values of the value datum. Keys that are defined in this hash:contentβ that's the actual content of the value element. This contains the value in a format suitable for display.valueβ this contains the unformatted value. For example, when bytes are displayed using"1M"or"1.1G", this will contain the value in bytes.totalβ this is used by values that represent an average. It contains the total which makes up the average.nβ this is used by values that represent an average. It contains the total which was used in the division to compute the average.col_infoβ theLire::ColumnInfoobject describing the column in which this name appears.
handle_summary_value( $value_rec )β called after a"value"element located in thegroup-summaryelement was parsed. The$value_recparameter is identical to the one in thehandle_value()method.handle_chart_configs( $configs )β if the Subreport contained chart configurations, an array reference ofLire::Report::ChartConfigobjects will be passed to this event handler.
π CONTEXT METHODS π«Ά
okay so last but definitely not least, here's a whole lil pile of extra methods you can hit up when you need to peek at some context info while you're processing elements. they're giving "backstage pass" energy β¨
current_subreport_count( )
returns how many subreports are present so far in the report. and bestie, listen β that number equals the number of processed "subreport" elements, which means the current subreport does not get counted until its closing tag has been processed. no cap, it's a "don't count your chickens" situation π
current_section_subreport_count( )
same vibe, different scope: returns how many subreports are present to date in the section. again, that's the number of processed "subreport" elements, so the current subreport isn't counted until the closing tag was processed. β
current_date( )
returns the content of the "date" element that applies to the current element. this will either be the current subreport's date, or the default one taken from the "report" element. π
the date comes back as a hash reference which will contain the formatted date in the "date" key, and the date in seconds since epoch in the "time" key. two keys, one iconic lil hash π
current_timespan( )
returns the content of the "timespan" element that applies to the current element. this will either be the current subreport's date, or the default one taken from the "report" element. (yes, it really does say "date" there β we're just relaying the vibes π)
the timespan comes back as a hash reference which will contain the formatted timespan in the "timespan" key. the starting and ending date of the timespan are available as seconds since epoch in the "start" and "end" keys. and the "period" key contains the report's timespan. so many keys, so little time πΈ
current_superservice( )
useful in "subreport" context β it returns the superservice's of the current subreport. π
current_type( )
useful in "subreport" context β it returns the ID of the report specification that was used to generate the current subreport. like a birth certificate for your subreport, fr fr π¦
current_table_info()
useful when processing "group" and "entry" β this returns a Lire::Report;:TableInfo object which describes the layout of the current table. layout intel, delivered π
current_group_entry_show( )
useful in "table" and "group" context β it returns the maximum number of entries that should be displayed. the ceiling. the limit. the "that's enough bestie" number β¨
show_current_entry( )
useful in "entry" context β this one's your vibe check: you can use it to test whether or not the current "entry" should be displayed, based on the current entry index and the parent's "show" attribute. lowkey the most useful lil boolean ever π
current_table_entry_count( )
useful in "table" context β it returns the number of entries that were processed so far. important caveat bestie: this only reports the entries in the "table" element, and it does not count the ones in the nested "group". read that twice, it's on the test π
π SEE ALSO π
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)
basically the whole friend group π«Ά
π AUTHOR π
Francis J. Lacoste <flacoste@logreport.org> β the main character who wrote this whole thing π
β VERSION β
$Id: ReportParser.pm,v 1.52 2006/07/23 13:16:29 vanbaal Exp $
π COPYRIGHT π
Copyright (C) 2001-2004 Stichting LogReport Foundation LogReport@LogReport.org
This file is part of Lire.
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.
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. (yes, that's the shouty legal bit β it means it, so don't come for me π)
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.
and that's the whole page bestie!! π§ this was Lire 2.1.1, dated 2025-09-28, and it's ReportParser(3pm) β go forth and parse some reports, you absolute icon ππΈβ¨
π¦ where this page comes from
- arch rolling: lire 2.1.1-8 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms