]> Dogcows Code - chaz/git-codeowners/blob - lib/App/Codeowners/Formatter/CSV.pm
fix printing wide char with YAML formatter
[chaz/git-codeowners] / lib / App / Codeowners / Formatter / CSV.pm
1 package App::Codeowners::Formatter::CSV;
2 # ABSTRACT: Format codeowners output as comma-separated values
3
4 =head1 DESCRIPTION
5
6 This is a L<App::Codeowners::Formatter> that formats output using L<Text::CSV>.
7
8 =cut
9
10 use warnings;
11 use strict;
12
13 our $VERSION = '9999.999'; # VERSION
14
15 use parent 'App::Codeowners::Formatter';
16
17 use App::Codeowners::Util qw(stringify);
18
19 sub start {
20 my $self = shift;
21
22 $self->text_csv->print($self->handle, $self->columns);
23 }
24
25 sub stream {
26 my $self = shift;
27 my $result = shift;
28
29 $self->text_csv->print($self->handle, [map { stringify($_) } @$result]);
30 }
31
32 =attr text_csv
33
34 Get the L<Text::CSV> instance.
35
36 =cut
37
38 sub text_csv {
39 my $self = shift;
40
41 $self->{text_csv} ||= do {
42 eval { require Text::CSV } or die "Missing dependency: Text::CSV\n";
43
44 my %options;
45 $options{escape_char} = $self->escape_char if $self->escape_char;
46 $options{quote} = $self->quote if $self->quote;
47 $options{sep} = $self->sep if $self->sep;
48 if ($options{sep} && $options{sep} eq ($options{quote} || '"')) {
49 die "Invalid separator value for CSV format.\n";
50 }
51
52 Text::CSV->new({binary => 1, eol => $/, %options});
53 } or die "Failed to construct Text::CSV object";
54 }
55
56 =attr sep
57
58 Get the value used for L<Text::CSV/sep>.
59
60 =attr quote
61
62 Get the value used for L<Text::CSV/quote>.
63
64 =attr escape_char
65
66 Get the value used for L<Text::CSV/escape_char>.
67
68 =cut
69
70 sub sep { $_[0]->{sep} || $_[0]->format }
71 sub quote { $_[0]->{quote} }
72 sub escape_char { $_[0]->{escape_char} }
73
74 1;
This page took 0.037967 seconds and 4 git commands to generate.