| 1 | # perl | ||
| 2 | # | ||
| 3 | # Minimal report example, data rows given as array reference | ||
| 4 | # | ||
| 5 | # PORF Perl Open Report Framework | ||
| 6 | # | ||
| 7 | # Ralf Peine, Wed May 14 10:39:47 2014 | ||
| 8 | # | ||
| 9 | #------------------------------------------------------------------------------ | ||
| 10 | |||
| 11 | use warnings; | ||
| 12 | use strict; | ||
| 13 | |||
| 14 | use Report::Porf::Framework; | ||
| 15 | |||
| 16 | # --- Run The Example ---------------------------------------- | ||
| 17 | sub run_example { | ||
| 18 | my $person_rows = shift; # Param1: Reference to list of arrays | ||
| 19 | my $format = shift; # Param2: Optional: format of report | ||
| 20 | |||
| 21 | $format = 'text' unless $format; | ||
| 22 | |||
| 23 | my $count_rows = scalar @{$person_rows}; | ||
| 24 | my $out_file_name = "result_minimal_array_${count_rows}.${format}"; | ||
| 25 | my $file_handle = FileHandle->new($out_file_name, 'w'); | ||
| 26 | |||
| 27 | print "Write into result file: $out_file_name\n"; | ||
| 28 | |||
| 29 | # --- create Report ------------------------------------------------------- | ||
| 30 | my $report_frame_work = Report::Porf::Framework::get(); | ||
| 31 | my $report = $report_frame_work->create_report($format); | ||
| 32 | |||
| 33 | # $report->set_verbose(3); # uncomment to see infos about configuring phase | ||
| 34 | |||
| 35 | # --- Configure Report ---------------------------------------------------- | ||
| 36 | |||
| 37 | my %idx = get_person_row_index_info(); | ||
| 38 | |||
| 39 | $report->configure_column(-header => 'Prename', -value_indexed => $idx{Prename} ); # long | ||
| 40 | $report->conf_col (-h => 'Surname', -val_idx => $idx{Surname} ); # short | ||
| 41 | $report->cc (-h => 'Age', -vi => $idx{Age} ); # minimal | ||
| 42 | |||
| 43 | $report->configure_complete(); | ||
| 44 | |||
| 45 | # --- print out table ----------------------------------- | ||
| 46 | |||
| 47 | $report->write_all($person_rows, $file_handle); | ||
| 48 | |||
| 49 | # --- return count of entries --------------------------- | ||
| 50 | |||
| 51 | return ($count_rows); | ||
| 52 | } | ||
| 53 | |||
| 54 | # --- can be defined anywhere and global for person_rows --- | ||
| 55 | sub get_person_row_index_info { | ||
| 56 | my %idx = ( | ||
| 57 | Count => 0, # not used! | ||
| 58 | Prename => 1, | ||
| 59 | Surname => 2, | ||
| 60 | Age => 3, | ||
| 61 | Time => 4, # not used! | ||
| 62 | ); | ||
| 63 | |||
| 64 | return %idx; | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; |