Ricardo Vazquez Armenta > Data-Reporter-1.4 > Data::Reporter



Annotate this POD

View/Report Bugs
Module Version: 1.4   Source  


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 :');

 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});

    $source = new Data::Reporter::Filesource(File => "inputfile");
    my $report = new Data::Reporter();
        Width => 105,
        Height => 66,
        SubHeaher => \&HEADER,
        SubTitle => \&TITLE,
        SubDetail => \&DETAIL,
        Source => $source,
        File_name => "OUPUT"



Creates a new Report handler

$report->configure(option => value)

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



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.



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.

syntax highlighting: