| 1 | package oEdtk::OmgrIdxDoc; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | our $VERSION = 2.1131; | |
| 6 | |||
| 7 | 1 | ▶ | use base 'oEdtk::Doc'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use oEdtk::Config qw(config_read); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use oEdtk::DBAdmin qw(@INDEX_COLS); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use oEdtk::Dict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use Text::CSV; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 0 | ▶ | sub new { |
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 14 | 0 | my ($class) = @_; | |
| 15 | |||
| 16 | 0 | my $self = {}; | |
| 17 | |||
| 18 | # fields => @fields, | ||
| 19 | # csv => $csv, | ||
| 20 | # header => $header | ||
| 21 | # }; | ||
| 22 | |||
| 23 | 0 | $self->{csv} = Text::CSV->new( { binary => 1, eol => "\n", quote_space => 0 } ); | |
| 24 | |||
| 25 | # my @fields = map { $row->{$$_[0]} } @INDEX_COLS; | ||
| 26 | 0 | $self->{fields} = [ map { $$_[0] } @INDEX_COLS ]; | |
| 27 | |||
| 28 | # my $status= $csv->combine ([map { $$_[0] } @INDEX_COLS]); | ||
| 29 | 0 | $self->{csv}->combine( @{ $self->{fields} } ); | |
| 30 | 0 | $self->{header} = $self->{csv}->string(); | |
| 31 | |||
| 32 | #my $toto = sprintf ("%s", ${self->{csv}}->string()); | ||
| 33 | # warn "DEBUG: header => " .$toto. "\n"; | ||
| 34 | #$csv->print($fh, [map { $$_[0] } @INDEX_COLS]); | ||
| 35 | |||
| 36 | 0 | bless $self, $class; | |
| 37 | 0 | $self->reset(); | |
| 38 | 0 | return $self; | |
| 39 | } | ||
| 40 | |||
| 41 | 0 | ▶ | sub mktag { |
|
Subroutine
mktag: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 42 | 0 | my ( $self, $name, $value ) = @_; | |
| 43 | 0 | $self->{idxTag}{$name} = $value; | |
| 44 | |||
| 45 | 0 | return $name; | |
| 46 | } | ||
| 47 | |||
| 48 | 0 | ▶ | sub reset { |
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 49 | 0 | my ($self) = @_; | |
| 50 | |||
| 51 | 0 | $self->{idxTag} = {}; | |
| 52 | } | ||
| 53 | |||
| 54 | 0 | ▶ | sub dump { |
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
documented
| |||
| 55 | 0 | my ($self) = @_; | |
| 56 | 0 | my @values; | |
| 57 | |||
| 58 | # my @fields = map { $row->{$$_[0]} } @INDEX_COLS; | ||
| 59 | # my $csv->print($fh, \@fields); | ||
| 60 | |||
| 61 | # ## my $doclib; | ||
| 62 | # while (my $row = $sth->fetchrow_hashref()) { | ||
| 63 | # # Gather the values in the same order as @INDEX_COLS. | ||
| 64 | # my @fields = map { $row->{$$_[0]} } @INDEX_COLS; | ||
| 65 | # $csv->print($fh, \@fields); | ||
| 66 | # ## $doclib = $row->{'ED_DOCLIB'} unless defined $doclib; | ||
| 67 | # } | ||
| 68 | |||
| 69 | # my $out = ''; | ||
| 70 | # foreach (@{$self->{'taglist'}}) { | ||
| 71 | 0 | foreach ( @{ $self->{'fields'} } ) { | |
| 72 | 0 | push( @values, $self->{idxTag}{$_} ); | |
| 73 | |||
| 74 | # my $tag = $_->emit; | ||
| 75 | # $out .= $tag; | ||
| 76 | } | ||
| 77 | 0 | my $status = $self->{csv}->combine(@values); | |
| 78 | |||
| 79 | 0 | return $self->{csv}->string(); | |
| 80 | } | ||
| 81 | |||
| 82 | 1 | 1; | |
| 83 | |||
| 84 | =head1 NAME | ||
| 85 | |||
| 86 | oEdtk::OmgrIdxDoc - Outmngr index document (CSV lines) | ||
| 87 | |||
| 88 | =head1 SYNOPSIS | ||
| 89 | |||
| 90 | use oEdtk::OmgrIdxDoc; | ||
| 91 | |||
| 92 | my $doc = oEdtk::OmgrIdxDoc->new; | ||
| 93 | $doc->mktag('ED_IDLDOC', $idldoc); | ||
| 94 | $doc->dump; # one CSV line, in @INDEX_COLS order | ||
| 95 | |||
| 96 | =head1 DESCRIPTION | ||
| 97 | |||
| 98 | An C<oEdtk::Doc> subclass that produces the index records consumed by | ||
| 99 | Outmngr. The column list and order come from C<@INDEX_COLS> in | ||
| 100 | C<oEdtk::DBAdmin>; each emitted document is a single CSV line built with | ||
| 101 | C<Text::CSV>. | ||
| 102 | |||
| 103 | =head1 METHODS | ||
| 104 | |||
| 105 | =head2 new | ||
| 106 | |||
| 107 | my $doc = oEdtk::OmgrIdxDoc->new; | ||
| 108 | |||
| 109 | Build the document, creating the C<Text::CSV> writer and the header line from | ||
| 110 | C<@INDEX_COLS>, and clear the tag hash. | ||
| 111 | |||
| 112 | =head2 mktag | ||
| 113 | |||
| 114 | my $name = $doc->mktag($name, $value); | ||
| 115 | |||
| 116 | Record the index value C<$value> under the column C<$name> and return C<$name>. | ||
| 117 | |||
| 118 | =head2 reset | ||
| 119 | |||
| 120 | $doc->reset; | ||
| 121 | |||
| 122 | Clear the recorded tag values. | ||
| 123 | |||
| 124 | =head2 dump | ||
| 125 | |||
| 126 | my $line = $doc->dump; | ||
| 127 | |||
| 128 | Return the recorded values, in C<@INDEX_COLS> order, combined into one CSV | ||
| 129 | line. | ||
| 130 | |||
| 131 | =head1 AUTHOR | ||
| 132 | |||
| 133 | The oEdtk team. | ||
| 134 | |||
| 135 | =cut | ||