| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::RecordStream::Operation::tohtml; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = "4.0.23"; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 2 |  |  | 2 |  | 914 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 50 |  | 
| 6 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 48 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 9 | use base qw(App::RecordStream::Operation); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1028 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub init { | 
| 11 | 5 |  |  | 5 | 0 | 10 | my $this = shift; | 
| 12 | 5 |  |  |  |  | 7 | my $args = shift; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 5 |  |  |  |  | 9 | my $no_header; | 
| 15 | 5 |  |  |  |  | 8 | my $row_attributes = ''; | 
| 16 | 5 |  |  |  |  | 8 | my $cell_attributes = ''; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 5 |  |  |  |  | 29 | my $key_groups = App::RecordStream::KeyGroups->new(); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | my $spec = { | 
| 21 | 2 |  |  | 2 |  | 1764 | 'keys|k|fields|f=s' => sub { $key_groups->add_groups($_[1]); }, | 
| 22 | 5 |  |  |  |  | 36 | 'noheader'          => \$no_header, | 
| 23 |  |  |  |  |  |  | 'rowattributes=s'   => \$row_attributes, | 
| 24 |  |  |  |  |  |  | 'cellattributes=s'  => \$cell_attributes, | 
| 25 |  |  |  |  |  |  | }; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 5 |  |  |  |  | 23 | $this->parse_options($args, $spec); | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 5 |  |  |  |  | 13 | $this->{'KEY_GROUPS'}      = $key_groups; | 
| 30 | 5 |  |  |  |  | 10 | $this->{'NO_HEADER'}       = $no_header; | 
| 31 | 5 |  |  |  |  | 10 | $this->{'ROW_ATTRIBUTES'}  = $row_attributes; | 
| 32 | 5 |  |  |  |  | 47 | $this->{'CELL_ATTRIBUTES'} = $cell_attributes; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub accept_record { | 
| 36 | 25 |  |  | 25 | 0 | 47 | my $this   = shift; | 
| 37 | 25 |  |  |  |  | 36 | my $record = shift; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 25 |  |  |  |  | 67 | $this->print_start($record); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 25 |  |  |  |  | 43 | my $fields          = $this->{'FIELDS'}; | 
| 42 | 25 |  |  |  |  | 43 | my $row_attributes  = $this->{'ROW_ATTRIBUTES'}; | 
| 43 | 25 |  |  |  |  | 42 | my $cell_attributes = $this->{'CELL_ATTRIBUTES'}; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 25 |  |  |  |  | 89 | $this->push_line(" | 
"); 
| 46 |  |  |  |  |  |  |  | 
| 47 | 25 |  |  |  |  | 50 | foreach my $field (@$fields) { | 
| 48 | 45 |  | 50 |  |  | 70 | my $value = ${$record->guess_key_from_spec($field)} || ''; | 
| 49 | 45 |  |  |  |  | 183 | $this->push_line(" | $value"); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 25 |  |  |  |  | 73 | $this->push_line(" | 
"); 
| 53 |  |  |  |  |  |  |  | 
| 54 | 25 |  |  |  |  | 154 | return 1; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub print_start { | 
| 58 | 25 |  |  | 25 | 0 | 41 | my $this   = shift; | 
| 59 | 25 |  |  |  |  | 38 | my $record = shift; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 25 | 100 |  |  |  | 65 | return if ( $this->{'PRINTED_START'} ); | 
| 62 | 5 |  |  |  |  | 16 | $this->{'PRINTED_START'} = 1; | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 5 |  |  |  |  | 20 | $this->push_line(" "); 
");
| 65 |  |  |  |  |  |  |  |  
| 66 | 5 |  |  |  |  | 10 | my $groups = $this->{'KEY_GROUPS'}; |  
| 67 | 5 | 100 |  |  |  | 16 | if ( $groups->has_any_group() ) { |  
| 68 | 2 |  |  |  |  | 8 | my $specs = $this->{'KEY_GROUPS'}->get_keyspecs($record); |  
| 69 | 2 |  |  |  |  | 5 | $this->{'FIELDS'} = $specs; |  
| 70 |  |  |  |  |  |  | } |  
| 71 |  |  |  |  |  |  | else { |  
| 72 | 3 |  |  |  |  | 20 | $this->{'FIELDS'} = [sort keys %$record]; |  
| 73 |  |  |  |  |  |  | } |  
| 74 |  |  |  |  |  |  |  |  
| 75 | 5 | 100 |  |  |  | 16 | return if ( $this->{'NO_HEADER'} ); |  
| 76 |  |  |  |  |  |  |  |  
| 77 | 4 |  |  |  |  | 12 | $this->print_header(); |  
| 78 |  |  |  |  |  |  | } |  
| 79 |  |  |  |  |  |  |  |  
| 80 |  |  |  |  |  |  | sub print_header { |  
| 81 | 4 |  |  | 4 | 0 | 45 | my $this = shift; |  
| 82 |  |  |  |  |  |  |  |  
| 83 | 4 |  |  |  |  | 28 | my $fields = $this->{'FIELDS'}; |  
| 84 |  |  |  |  |  |  |  |  
| 85 | 4 |  |  |  |  | 9 | my $row_attributes  = $this->{'ROW_ATTRIBUTES'}; |  
| 86 | 4 |  |  |  |  | 8 | my $cell_attributes = $this->{'CELL_ATTRIBUTES'}; |  
| 87 |  |  |  |  |  |  |  |  
| 88 | 4 |  |  |  |  | 17 | $this->push_line(" |  "); 
 
| 89 |  |  |  |  |  |  |  |  
| 90 | 4 |  |  |  |  | 9 | foreach my $field (@$fields) { |  
| 91 | 7 |  |  |  |  | 24 | $this->push_line(" | $field"); |  
| 92 |  |  |  |  |  |  | } |  
| 93 |  |  |  |  |  |  |  |  
");| 94 | 4 |  |  |  |  | 10 | $this->push_line(" |  
| 95 |  |  |  |  |  |  | } |  
| 96 |  |  |  |  |  |  |  |  
| 97 |  |  |  |  |  |  | sub stream_done { |  
| 98 | 5 |  |  | 5 | 0 | 10 | my $this = shift; |  
| 99 | 5 |  |  |  |  | 12 | $this->push_line(" |  | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | sub add_help_types { | 
| 103 | 5 |  |  | 5 | 0 | 8 | my $this = shift; | 
| 104 | 5 |  |  |  |  | 23 | $this->use_help_type('keyspecs'); | 
| 105 | 5 |  |  |  |  | 17 | $this->use_help_type('keygroups'); | 
| 106 | 5 |  |  |  |  | 13 | $this->use_help_type('keys'); | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub usage { | 
| 110 | 0 |  |  | 0 | 0 |  | my $this = shift; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 0 |  |  |  |  |  | my $options = [ | 
| 113 |  |  |  |  |  |  | ['keys ', 'Keys to print in the table.  May be specified multiple times, may be comma separated.  Default to all fields in the first record.  May be a keyspec or a keygroup, see \'--help-keys\' for more information'], | 
| 114 |  |  |  |  |  |  | ['noheader', 'Do not print the header row'], | 
| 115 |  |  |  |  |  |  | ['rowattributes', 'HTML attributes to put on the tr tags'], | 
| 116 |  |  |  |  |  |  | ['cellattributes', 'HTML attributes to put on the td and th tag'], | 
| 117 |  |  |  |  |  |  | ]; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  |  | my $args_string = $this->options_string($options); | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 0 |  |  |  |  |  | return < | 
| 122 |  |  |  |  |  |  | Usage: recs-totable  [] | 
| 123 |  |  |  |  |  |  | __FORMAT_TEXT__ | 
| 124 |  |  |  |  |  |  | Prints out an html table for the records from input or from . | 
| 125 |  |  |  |  |  |  | __FORMAT_TEXT__ | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | $args_string | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Examples: | 
| 130 |  |  |  |  |  |  | Print all fields | 
| 131 |  |  |  |  |  |  | recs-tohhtml | 
| 132 |  |  |  |  |  |  | Print foo and bar fields, without a header | 
| 133 |  |  |  |  |  |  | recs-tohtml --fields foo,bar --noheader | 
| 134 |  |  |  |  |  |  | USAGE | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | 1; |