The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Reporter - Report generator.

SYNOPSIS

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

DESCRIPTION

Data::Reporter::new();

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

SPECIAL FUNCTIONS

  • $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.

EVENT FUNCTIONS

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

HEADER FUNCTION

This functions is called each time when a new page is required

TITLE FUNCTION

This function is called after the header, and breaks functions.

DETAIL FUNCTION

This function is called for every data record

This functions is called at the end of each page

FINAL FUNCTION

This function is called after the last record has been processed for the detail function

BREAK FUNTIONS

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.

BREAKS

GENERALS

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.

CASCADE BREAKS

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.

DATASOURCES

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:

Around line 51:

'=item' outside of any '=over'

Around line 57:

You can't have =items (as at line 61) unless the first thing after the =over is an =item

Around line 120:

Expected text after =item, not a bullet

Around line 124:

You forgot a '=back' before '=head1'

Around line 126:

'=item' outside of any '=over'

Around line 181:

You forgot a '=back' before '=head1'

Around line 207:

You forgot a '=back' before '=head2'

Around line 231:

=back without =over

Around line 235:

'=item' outside of any '=over'

Around line 288:

You forgot a '=back' before '=head1'