File Coverage

blib/lib/Data/Record/Serialize/Role/Encode/CSV.pm
Criterion Covered Total %
statement 24 25 96.0
branch 0 2 0.0
condition n/a
subroutine 9 10 90.0
pod 0 2 0.0
total 33 39 84.6


line stmt bran cond sub pod time code
1              
2             # ABSTRACT: encode a record as csv
3              
4             use Moo::Role;
5 2     2   1036  
  2         5  
  2         13  
6             use Data::Record::Serialize::Error { errors => ['csv_backend'] }, -all;
7 2     2   809 use Types::Common::String qw( NonEmptyStr );
  2         5  
  2         48  
8 2     2   2536 use Types::Standard qw( Bool );
  2         53937  
  2         35  
9 2     2   1228  
  2         5  
  2         15  
10             use Text::CSV;
11 2     2   3141  
  2         27420  
  2         101  
12             use namespace::clean;
13 2     2   50  
  2         7  
  2         24  
14             our $VERSION = '0.02';
15              
16              
17 3     3   2625 has binary => (
18             is => 'ro',
19             isa => Bool,
20             default => 1,
21             );
22              
23             has sep_char => (
24             is => 'ro',
25             default => ','
26             );
27              
28             has quote_char => (
29             is => 'ro',
30             default => '"'
31             );
32              
33             has escape_char => (
34             is => 'ro',
35             default => '"'
36             );
37              
38             has always_quote => (
39             is => 'ro',
40             isa => Bool,
41             default => 0,
42             );
43              
44             has quote_empty => (
45             is => 'ro',
46             isa => Bool,
47             default => 0,
48             );
49              
50             has _csv => (
51             is => 'lazy',
52             init_arg => undef,
53             );
54              
55              
56             my $self = shift;
57 0 0   0 0 0  
58             my %args = (
59             binary => $self->binary,
60 2     2   27 sep_char => $self->sep_char,
61             quote_char => $self->quote_char,
62 2         45 escape_char => $self->escape_char,
63             always_quote => $self->always_quote,
64             quote_empty => $self->quote_empty,
65             auto_diag => 2,
66             );
67              
68             return Text::CSV->new( \%args );
69             }
70              
71             my $self = shift;
72 2         26 $self->_csv->say( $self->fh, $self->output_fields );
73             }
74              
75              
76 2     2 0 80844  
77 2         44  
78              
79              
80              
81              
82              
83              
84             1;
85              
86             #
87             # This file is part of Data-Record-Serialize-Encode-csv
88             #
89             # This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
90             #
91             # This is free software, licensed under:
92             #
93             # The GNU General Public License, Version 3, June 2007
94             #
95              
96              
97             =pod
98              
99             =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory
100              
101             =head1 NAME
102              
103             Data::Record::Serialize::Role::Encode::CSV - encode a record as csv
104              
105             =head1 VERSION
106              
107             version 0.02
108              
109             =head1 SYNOPSIS
110              
111             use Data::Record::Serialize;
112              
113             my $s = Data::Record::Serialize->new( encode => 'csv', ... );
114              
115             $s->send( \%record );
116              
117             =head1 DESCRIPTION
118              
119             B<Data::Record::Serialize::Encode::csv> encodes a record as CSV (well
120             anything that L<Text::CSV> can write).
121              
122             It performs the L<Data::Record::Serialize::Role::Encode> role.
123              
124             =for Pod::Coverage encode
125             send
126             setup
127             to_bool
128              
129             =head1 CONSTRUCTOR OPTIONS
130              
131             =head2 L<Text::CSV> Options
132              
133             These are passed through to L<Text::CSV>:
134              
135             =over
136              
137             =item binary => I<Boolean>
138              
139             Default: I<true>
140              
141             =item sep_char => I<character>
142              
143             Default: C<,>
144              
145             =item quote_char => I<character>
146              
147             Default: C<">
148              
149             =item escape_char => i<character>
150              
151             Default: C<">
152              
153             =item always_quote => I<Boolean>
154              
155             Default: I<false>
156             q
157              
158             =item quote_empty => I<Boolean>
159              
160             Default: I<false>
161              
162             =back
163              
164             =head1 SUPPORT
165              
166             =head2 Bugs
167              
168             Please report any bugs or feature requests to bug-data-record-serialize-encode-csv@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize-Encode-csv
169              
170             =head2 Source
171              
172             Source is available at
173              
174             https://gitlab.com/djerius/data-record-serialize-encode-csv
175              
176             and may be cloned from
177              
178             https://gitlab.com/djerius/data-record-serialize-encode-csv.git
179              
180             =head1 SEE ALSO
181              
182             Please see those modules/websites for more information related to this module.
183              
184             =over 4
185              
186             =item *
187              
188             L<Data::Record::Serialize::Encode::csv|Data::Record::Serialize::Encode::csv>
189              
190             =back
191              
192             =head1 AUTHOR
193              
194             Diab Jerius <djerius@cpan.org>
195              
196             =head1 COPYRIGHT AND LICENSE
197              
198             This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
199              
200             This is free software, licensed under:
201              
202             The GNU General Public License, Version 3, June 2007
203              
204             =cut