|
Reporter - Report generator. |
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();
}
valid options are:
# 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})
generate() Generates the report. Returns 0 if OK, 2 if there was no data
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
time(n) returns the time in a specific format. n is the format code. Currently, there is only 1 format
1 hh:mm
eOR() indicates the end of report
bOR() indicates the begining of the report
bOP() indicates the firts detail in the the page
width() Report's width
height() Report's height
islastbreak() Returns true if it's the last processing break (using the cascade breaks approach)
iPB() Returns true if the reporter is processing breaks (useful when you want or not to do something while processing breaks)
newpage([TIMES]) indicates that a new page is required. TIMES is the number of form feeds to do. By default is 1
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:
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.
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.
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.
|
Reporter - Report generator. |