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