PostScript::Report::Builder - Build a PostScript::Report object
This document describes version 0.11 of PostScript::Report::Builder, released April 27, 2013 as part of PostScript-Report version 0.11.
use PostScript::Report (); my $rpt = PostScript::Report->build(\%report_description);
Because a PostScript::Report involves constructing a number of related objects, it's usually more convenient to pass a description of the report to a builder object.
You can find example reports in the examples directory of this distribution.
The %report_description is a hash with keys as follows:
%report_description
Any of the Report attributes listed under "Report Formatting" in PostScript::Report or "Component Formatting" in PostScript::Report may be set by the report description.
Any of the attributes listed in "ATTRIBUTES" may be set by the report description when build is called as a class method.
build
All fonts used in a report must be defined in a hashref under the fonts key (unless you only want to use the report's default fonts). The keys in this hashref are arbitrary strings, and the values are strings in the form FONTNAME-SIZE.
fonts
If you use the same value more than once, then both keys will refer to the same font object. This allows you to use the same font for different purposes, while retaining the ability to substitute a different font for one of those purposes just by changing the fonts hash.
When you set a font or label_font attribute, its value must be one of the keys in the fonts hash.
font
label_font
Example:
fonts => { label => 'Helvetica-6', text => 'Helvetica-9', }, font => 'text', label_font => 'label',
Any of the sections listed under "Report Sections" in PostScript::Report may be defined by the report description. The value is interpreted as follows:
Components are created by hashrefs. Containers are created by arrayrefs.
If the section is a container, the initial container type is chosen like this: If the first value in the arrayref is a hashref, you get an HBox. Otherwise, you get a VBox.
After that, the box types alternate. If you place an arrayref in an HBox, it becomes a VBox. An arrayref in a VBox becomes an HBox.
You can override the box type (or pass parameters to its constructor), by making the first entry in the arrayref a string (the container type) and the second entry a hashref to pass to its constructor. If that hashref contains a _default key, its value becomes the default component class inside this container.
_default
The hashref that represents a Component is simply passed to its constructor, with one exception. If the hash contains the _class key, that value is removed and used as the class name.
_class
As a special case, you can pass a scalar reference as the value for a Component. This creates a constant value. That is,
value
value => \'Label:',
is equivalent to
value => { _class => 'Constant', value => 'Label:' },
Anywhere you specify a class name, PostScript::Report:: is automatically prepended to the name you give. To use a class outside that namespace, prefix the class name with =.
PostScript::Report::
=
There are two exceptions to this:
When you give a hashref as the value of a value attribute, the prefix is PostScript::Report::Value:: instead of just PostScript::Report::.
PostScript::Report::Value::
The report_class is always a complete class name.
report_class
The columns key is provided as a shortcut for the common case of a report with column headers and a single-row detail section.
columns
detail
The value should be a hashref with the following keys:
A hashref of parameters to pass to the constructor of the HBox that holds the column headers. Optional.
A hashref of parameters to pass to the constructor of the HBox that forms the detail section. Optional.
An arrayref of arrayrefs, one per column. Required. Each arrayref has 4 elements. The first two are the column title and the column width. The third is an optional hashref of parameters for the header component, and the fourth is an optional hashref of parameters for the detail component.
If you don't specify a _class for the header component, it defaults to "default_column_header", and if you don't specify a _class for the detail component, it defaults to "default_column_type".
If you don't specify a value for the header component, it defaults to the column title (as a Constant).
If you don't specify a value for the detail component, it defaults to the next column number. (If you do specify a value, the column number is not incremented.)
This assumes that the page_header is a VBox (or that there is no page_header aside from the column headers).
page_header
If you need a more complex layout than this, don't use columns. Instead, define the detail and page_header sections as needed.
The stripe and stripe_page keys are provided as a shortcut for the common case of a report with a detail section that cycles through a pattern of background colors.
stripe
stripe_page
The value should be a arrayref of colors. The first row uses the first color, the second row uses the second color, and so on (wrapping around to the beginning of the array).
Use stripe_page if you want the pattern to start over on every page, or stripe if you want it to continue from where the previous page left off.
For example,
stripe => [ 1, 0.85 ],
will give every other row a light grey background.
If you need a more complex color scheme, set "detail_background" in PostScript::Report directly.
Note that stripe and stripe_page are not placed inside the columns hash, because they can be used even if you define the detail section manually.
This is the default component class used for column headers. It defaults to Field.
This is the default component class used for column fields. It defaults to Field.
This is the default component class used when building the report sections. It defaults to Field.
You can temporarily override this by specifying the _default key as a container's parameter.
This is the class of object that will be constructed. It defaults to PostScript::Report. This must always be a full class name.
$rpt = $builder->build(\%report_description) $rpt = PostScript::Report::Builder->build(\%report_description)
This can be called as either an object or class method. When called as a class method, it constructs a temporary object by passing the description to new.
new
PostScript::Report::Builder requires no configuration files or environment variables.
None reported.
No bugs have been reported.
Christopher J. Madsen <perl AT cjmweb.net>
<perl AT cjmweb.net>
Please report any bugs or feature requests to <bug-PostScript-Report AT rt.cpan.org> or through the web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=PostScript-Report.
<bug-PostScript-Report AT rt.cpan.org>
You can follow or contribute to PostScript-Report's development at http://github.com/madsen/postscript-report.
I'd like to thank Micro Technology Services, Inc. http://www.mitsi.com, who sponsored development of PostScript-Report, and fREW Schmidt, who recommended me for the job. It wouldn't have happened without them.
This software is copyright (c) 2013 by Christopher J. Madsen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
To install PostScript::Report, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PostScript::Report
CPAN shell
perl -MCPAN -e shell install PostScript::Report
For more information on module installation, please visit the detailed CPAN module installation guide.