Reporter - Report generator.
use strict; use Data::Reporter::RepFormat; use Data::Reporter; use Data::Reporter::Filesource; sub HEADER($$$$) { my ($reporter, $sheet, $rep_actline, $rep_lastline) = @_; $sheet->MVPrint(10,0, 'This is the header'); $sheet->MVPrint(10,1, 'This is the page :'); $sheet->Print($reporter->page()); } sub TITLE($$$$) { my ($reporter, $sheet, $rep_actline, $rep_lastline) = @_; $sheet->MVPrint(10,0, 'This is the title'); } sub DETAIL($$$$) { my ($reporter, $sheet, $rep_actline, $rep_lastline) = @_; $sheet->MVPrint(10,0, 'This is the detail'); $sheet->MVPrint(10,1, 'This is the begin of the report') if ($reporter->{BOR}); } #main { $source = new Data::Reporter::Filesource(File => "inputfile"); my $report = new Data::Reporter(); $report->configure( Width => 105, Height => 66, SubHeaher => \&HEADER, SubTitle => \&TITLE, SubDetail => \&DETAIL, Source => $source, File_name => "OUPUT" ); $report->generate(); }
Creates a new Report handler
valid options are:
Width number of columns
Height number of rows
Orientation Report orientation (portrait, landscape)
Footer_size rows in footer
File_name output file name
Source Data source (Datasource class descendant)
Breaks Hash reference, which contains the breaks information
SubHeader function reference, which will be called to print the report header
SubTitle function reference, which will be called to print the report title
SubDetail function reference, which will be called to print every report detail
SubFooter function reference, which will be called to print the report footer
SubFinal function reference, which is called when all data has been processed
SubPrint function reference, which is called when the report is created
# als, 2001-04-10 =item
User_data hash reference with data that can be used in each function called during the creation of the report ($hash_ref = $self->[USER_DATA]; $hash_ref->{my_data})
$report->generate() Generates the report. Returns 0 if OK, 2 if there was no data
$report->page() returns the page number
# als, 2001-02-16 $report->date(n) returns the date in a specific format. n is the format code. Currently, there are only 3 formats
1 dd/mm/aaaa 2 mm/dd/aaaa 3 aaaa-mm-dd
$report->time(n) returns the time in a specific format. n is the format code. Currently, there is only 1 format
1 hh:mm
$report->eOR() indicates the end of report
$report->bOR() indicates the begining of the report
$report->bOP() indicates the firts detail in the the page
$report->width() Report's width
$report->height() Report's height
$report->islastbreak() Returns true if it's the last processing break (using the cascade breaks approach)
$report->iPB() Returns true if the reporter is processing breaks (useful when you want or not to do something while processing breaks)
$report->newpage([TIMES]) indicates that a new page is required. TIMES is the number of form feeds to do. By default is 1
$report->newreport(FILE) indicates that the data processed up to this point should be stored in file FILE.
Each event function (Header, Title, Detail, Break, Foooter, Final), is called automatically when neccesary, passing them the following parameters:
report which can be used to access the special variables
sheet blank sheet where the output will be defined (see RepFormat pod documentation)
actual_reg actual processing register
last_reg last processing register
This functions is called each time when a new page is required
This function is called after the header, and breaks functions.
This function is called for every data record
This functions is called at the end of each page
This function is called after the last record has been processed for the detail function
These functions are called when the break field of the function has changed (see BREAKS section). These functions are called before the detail function for the actual register.
Each break is defined with a break field and a break function. For example:
assume we have the following data:
1 2 1 3 2 4
If we want a break for the first field, that prints the sum of the second field, we have to define the following hash
$breaks{0} = \&sub_break;
where sub_break is the function where the output is defined. We have to define the sum for each record in the 'detail' function
sub detail ( ..... ... $sum += $field[1]; ....
so we can do
sub sub_break ( .... ... $sheet->Print("the sum is $sum"); $sum = 0; #reset $sum ...
As many breaks as necessary can be defined, but only one break per field is allowed.
When defining more that one Break, they are handled in cascade. A change in a break field will cause all the break functions defined for fields with a lower value to be called. For example
assume the following data
1 2 3 1 1 1 2 3 1 2 1 2 4 2 3 1 3 4 2 4
and the following break hash
$breaks{0} = \&break1; $breaks{1} = \&break2; $breaks{3} = \&break3;
in the third register, the field #3 changes. This will cause the functions break1, break2 and break3 to be called. The order in which these functions are called are from the left most to the right most one.
In the fourth register the field #2 changes, so functions break1 and break2 will be called, in this order.
This indicates the source for the report data. It can be a Database or a plain ascii file.
Internally, Data::Reporter uses this object to retreive data. This object should have a function 'getdata' defined, which receives a function reference that will be called on each record.
This approach allows to have diferent data sources. At this point the only sources available are a Sybase database and a plain ascii file, but sources for others databases can easily be implemented.
10 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You can't have =items (as at line 61) unless the first thing after the =over is an =item
Expected text after =item, not a bullet
You forgot a '=back' before '=head1'
You forgot a '=back' before '=head2'
=back without =over
To install Data::Reporter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Reporter
CPAN shell
perl -MCPAN -e shell install Data::Reporter
For more information on module installation, please visit the detailed CPAN module installation guide.