PDF::ReportWriter::Datasource
PDF::ReportWriter::Datasource is a PDF::ReportWriter class that represents a (mmh) data source. Every Datasource class provides all needed information to extract data to be used in the report. The interface it exposes, that obviously can be overloaded with subclasses, is composed of several methods. The most important is the get_data() method.
get_data()
This class is designed in a way that should be simple to be overloaded, and thus provide alternative classes that provide data for the report in a totally different way.
An example of this concept is given in the PDF::Report::Datasource::DBI class.
PDF::Report::Datasource::DBI
There is really no usage for this class, because it is autoloaded and invoked automatically by PDF::ReportWriter::Report object when needed. If you really want an example of usage, here it is:
PDF::ReportWriter::Report
# Create a datasource object my $my_ds = PDF::ReportWriter::Datasource->new({ type => 'DBI', dsn => 'DBI:Pg:dbname=pdfrwtest', user => 'postgres', pass => 'postgres', }); $my_ds->get_data();
Creates a new PDF::ReportWriter::Datasource object. options is a hash reference. Its only required key is type, which identifies the correct subclass name (for example, DBI). Every subclass can have its own options that you need to pass in order to make everything work as expected. Typical usage of Datasource class is not through new() constructor, but through xml report definition. Including the following fragment of code in your xml report in the data section, automatically creates needed objects and uses them:
options
type
DBI
new()
data
<report> ... <data> ... <datasource name="customer"> <type>DBI</type> <dsn>DBI:Pg:dbname=accounting</dsn> <user>postgres</user> <pass>postgres</pass> <sql>SELECT * FROM customers WHERE id=?</sql> <attr> <ChopBlanks>1</ChopBlanks> <PrintError>1</PrintError> <RaiseError>1</RaiseError> </attr> </datasource> </data> ... </report>
Should be used to provide all actual data records to the report. You can do anything you want with this. A typical use is to connect to a DBI data source and return the result of selectall_arrayref(). Check PDF::ReportWriter::Datasource::DBI for actual code that does this.
selectall_arrayref()
PDF::ReportWriter::Datasource::DBI
The default implementation returns no record. If no datasource is defined in your report, you can directly supply the optional data_records parameter to render_report() method. See PDF::ReportWriter::render_report().
data_records
render_report()
PDF::ReportWriter::render_report()
It is called automatically just after get_data(), to make additional processing over raw data returned by Datasource. It is meant to allow easy overloading of classes without rewriting of get_data() method. Example: converting all dates to a custom format not supported by underlying database.
Default implementation does nothing.
Allows to replace placeholders. Check PDF::ReportWriter::Datasource::DBI.
The design of PDF::ReportWriter::Datasource allows one to build a custom class that provides alternative behavior for get_data() method.
replace_input_values()
1 POD Error
The following errors were encountered while parsing the POD:
=over should be: '=over' or '=over positive_number'
To install PDF::ReportWriter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDF::ReportWriter
CPAN shell
perl -MCPAN -e shell install PDF::ReportWriter
For more information on module installation, please visit the detailed CPAN module installation guide.