| 1 | # perl | ||
| 2 | # | ||
| 3 | # Report example, data rows given as object reference | ||
| 4 | # | ||
| 5 | # PORF Perl Open Report Framework | ||
| 6 | # | ||
| 7 | # Ralf Peine, Wed May 14 10:39:46 2014 | ||
| 8 | # | ||
| 9 | #------------------------------------------------------------------------------ | ||
| 10 | |||
| 11 | use warnings; | ||
| 12 | use strict; | ||
| 13 | |||
| 14 | use Report::Porf::Framework; | ||
| 15 | |||
| 16 | sub run_example { | ||
| 17 | my $person_rows = shift; # Param1: Reference to list of objects | ||
| 18 | my $format = shift; # Param2: Optional: format of report | ||
| 19 | |||
| 20 | my $count_rows = scalar @{$person_rows}; | ||
| 21 | |||
| 22 | $format = 'text' unless $format; | ||
| 23 | |||
| 24 | # --- create Report ------------------------------------------------------- | ||
| 25 | my $report_frame_work = Report::Porf::Framework::get(); | ||
| 26 | my $report_configurator = $report_frame_work->create_report_configurator($format); | ||
| 27 | |||
| 28 | # $report->set_verbose(3); # uncomment to see infos about configuring phase | ||
| 29 | |||
| 30 | # --- Configure Report ---------------------------------------------------- | ||
| 31 | |||
| 32 | $report_configurator->set_alternate_row_colors('#EEEEEE', '#FFFFFF', '#DDDDFF') | ||
| 33 | if $report_configurator->can ('set_alternate_row_colors'); | ||
| 34 | |||
| 35 | my $report = $report_configurator->create_and_configure_report(); | ||
| 36 | |||
| 37 | if (lc($format) eq 'text') { | ||
| 38 | $report->set_header_row_start("@"); # overwrite default | ||
| 39 | $report->set_header_end (" @"); # overwrite default | ||
| 40 | } | ||
| 41 | |||
| 42 | # --- configure table ----------------------------------- | ||
| 43 | |||
| 44 | $report->configure_column(-header => 'Count', -align => 'Center', -value => sub { return $_[0]->get_count(); } ); | ||
| 45 | $report->configure_column(-header => 'TimeStamp', -w => 16, -a => 'R', -format => "%.5e sec", | ||
| 46 | -color => "#CCEECC", -v => '$_[0]->get_time()' ); | ||
| 47 | |||
| 48 | $report->configure_column(-h => 'Age', -w => 15, | ||
| 49 | -a => 'R', -f => "%.3f years", -vo => 'get_age()', | ||
| 50 | -c => sub { return $_[0]->get_age() >= 20 ? "": '#EECCCC'; } ); # Coloring by condition | ||
| 51 | |||
| 52 | $report->configure_column(-h => 'Prename', -w => 11, -a => 'l', -value_object => 'get_prename()' ); | ||
| 53 | $report->configure_column(-h => 'Surname', -width => 8, -val_obj => 'get_surname()' ); | ||
| 54 | |||
| 55 | $report->configure_complete(); | ||
| 56 | |||
| 57 | # --- print out table under own control ----------------------------------- | ||
| 58 | |||
| 59 | print($report->get_output_start()); | ||
| 60 | |||
| 61 | foreach my $data (@{$person_rows}) { | ||
| 62 | print($report->get_row_output($data)); | ||
| 63 | } | ||
| 64 | |||
| 65 | print($report->get_output_end()); | ||
| 66 | |||
| 67 | # --- return count of entries --------------------------- | ||
| 68 | |||
| 69 | return ($count_rows); | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; |