]> Dogcows Code - chaz/git-codeowners/blob - lib/App/Codeowners/Formatter/CSV.pm
Version 0.47
[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
5 use warnings;
6 use strict;
7
8 our $VERSION = '0.47'; # VERSION
9
10 use parent 'App::Codeowners::Formatter';
11
12 use App::Codeowners::Util qw(stringify);
13 use Encode qw(encode);
14
15 sub start {
16 my $self = shift;
17
18 $self->text_csv->print($self->handle, $self->columns);
19 }
20
21 sub stream {
22 my $self = shift;
23 my $result = shift;
24
25 $self->text_csv->print($self->handle, [map { encode('UTF-8', stringify($_)) } @$result]);
26 }
27
28
29 sub text_csv {
30 my $self = shift;
31
32 $self->{text_csv} ||= do {
33 eval { require Text::CSV } or die "Missing dependency: Text::CSV\n";
34
35 my %options;
36 $options{escape_char} = $self->escape_char if $self->escape_char;
37 $options{quote} = $self->quote if $self->quote;
38 $options{sep} = $self->sep if $self->sep;
39 if ($options{sep} && $options{sep} eq ($options{quote} || '"')) {
40 die "Invalid separator value for CSV format.\n";
41 }
42
43 Text::CSV->new({binary => 1, eol => $/, %options});
44 } or die "Failed to construct Text::CSV object";
45 }
46
47
48 sub sep { $_[0]->{sep} || $_[0]->format }
49 sub quote { $_[0]->{quote} }
50 sub escape_char { $_[0]->{escape_char} }
51
52 1;
53
54 __END__
55
56 =pod
57
58 =encoding UTF-8
59
60 =head1 NAME
61
62 App::Codeowners::Formatter::CSV - Format codeowners output as comma-separated values
63
64 =head1 VERSION
65
66 version 0.47
67
68 =head1 DESCRIPTION
69
70 This is a L<App::Codeowners::Formatter> that formats output using L<Text::CSV>.
71
72 =head1 ATTRIBUTES
73
74 =head2 text_csv
75
76 Get the L<Text::CSV> instance.
77
78 =head2 sep
79
80 Get the value used for L<Text::CSV/sep>.
81
82 =head2 quote
83
84 Get the value used for L<Text::CSV/quote>.
85
86 =head2 escape_char
87
88 Get the value used for L<Text::CSV/escape_char>.
89
90 =head1 BUGS
91
92 Please report any bugs or feature requests on the bugtracker website
93 L<https://github.com/chazmcgarvey/git-codeowners/issues>
94
95 When submitting a bug or request, please include a test-file or a
96 patch to an existing test-file that illustrates the bug or desired
97 feature.
98
99 =head1 AUTHOR
100
101 Charles McGarvey <chazmcgarvey@brokenzipper.com>
102
103 =head1 COPYRIGHT AND LICENSE
104
105 This software is copyright (c) 2019 by Charles McGarvey.
106
107 This is free software; you can redistribute it and/or modify it under
108 the same terms as the Perl 5 programming language system itself.
109
110 =cut
This page took 0.043825 seconds and 4 git commands to generate.