| 1 | package Data::Record::Serialize::Role::Encode::CSV; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: encode a record as csv | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Data::Record::Serialize::Error { errors => ['csv_backend'] }, -all; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Types::Common::String qw( NonEmptyStr ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use Types::Standard qw( Bool ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 5 | ▶ | use Text::CSV; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 5 | our $VERSION = '0.03'; | |||||||||
| 16 | |||||||||||
| 17 | 6 | ▶ | sub _needs_eol { 1 } | ||||||||
|
Subroutine
_needs_eol: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 5 | has binary => ( | |||||||||
| 20 | is => 'ro', | ||||||||||
| 21 | isa => Bool, | ||||||||||
| 22 | default => 1, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 5 | has sep_char => ( | |||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | default => ',' | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 5 | has quote_char => ( | |||||||||
| 31 | is => 'ro', | ||||||||||
| 32 | default => '"' | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 5 | has escape_char => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | default => '"' | ||||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | 5 | has always_quote => ( | |||||||||
| 41 | is => 'ro', | ||||||||||
| 42 | isa => Bool, | ||||||||||
| 43 | default => 0, | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | 5 | has quote_empty => ( | |||||||||
| 47 | is => 'ro', | ||||||||||
| 48 | isa => Bool, | ||||||||||
| 49 | default => 0, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 5 | has _csv => ( | |||||||||
| 53 | is => 'lazy', | ||||||||||
| 54 | init_arg => undef, | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub to_bool { $_[0] ? 1 : 0 } | ||||||||
|
Subroutine
to_bool: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 3 | ▶ | sub _build__csv { | ||||||||
|
Subroutine
_build__csv: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 3 | my $self = shift; | |||||||||
| 61 | |||||||||||
| 62 | 3 | my %args = ( | |||||||||
| 63 | binary => $self->binary, | ||||||||||
| 64 | sep_char => $self->sep_char, | ||||||||||
| 65 | quote_char => $self->quote_char, | ||||||||||
| 66 | escape_char => $self->escape_char, | ||||||||||
| 67 | always_quote => $self->always_quote, | ||||||||||
| 68 | quote_empty => $self->quote_empty, | ||||||||||
| 69 | auto_diag => 2, | ||||||||||
| 70 | ); | ||||||||||
| 71 | |||||||||||
| 72 | 3 | return Text::CSV->new( \%args ); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 3 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 76 | 3 | my $self = shift; | |||||||||
| 77 | 3 | ▶ | $self->_csv->combine( @{ $self->output_fields } ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | or croak( 'error creating CSV header' ); | ||||||||||
| 79 | 3 | $self->say( $self->_csv->string ); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | 5 | 1; | |||||||||
| 92 | |||||||||||
| 93 | # | ||||||||||
| 94 | # This file is part of Data-Record-Serialize-Encode-csv | ||||||||||
| 95 | # | ||||||||||
| 96 | # This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory. | ||||||||||
| 97 | # | ||||||||||
| 98 | # This is free software, licensed under: | ||||||||||
| 99 | # | ||||||||||
| 100 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 101 | # | ||||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||