]>
Dogcows Code - chaz/git-codeowners/blob - lib/App/Codeowners/Formatter.pm
095a6efa293b23a79c921a1c335822be8fe359a3
1 package App
::Codeowners
::Formatter
;
2 # ABSTRACT: Base class for formatting codeowners output
8 our $VERSION = '0.42'; # VERSION
15 my $args = {@_ == 1 && ref $_[0] eq 'HASH' ? %{$_[0]} : @_};
17 $args->{results
} = [];
19 # see if we can find a better class to bless into
20 ($class, my $format) = $class->_best_formatter($args->{format
}) if $args->{format
};
21 $args->{format
} = $format;
23 my $self = bless $args, $class;
31 # Find a formatter that can handle the format requested.
34 my $type = shift || '';
36 return ($class, $type) if $class ne __PACKAGE__
;
38 my ($name, $format) = $type =~ /^([A-Za-z]+)(?::(.*))?$/;
47 my @formatters = $class->formatters;
49 # default to the string formatter since it has no dependencies
50 my $package = __PACKAGE__
.'::String';
52 # look for a formatter whose name matches the format
53 for my $formatter (@formatters) {
54 my $module = lc($formatter);
57 if ($module eq $name) {
58 $package = $formatter;
65 return ($package, $type);
71 my $global_destruction = shift;
73 return if $global_destruction;
75 my $results = $self->{results
};
76 $self->finish($results) if $results;
77 delete $self->{results
};
81 sub handle
{ shift-
>{handle
} }
82 sub format
{ shift-
>{format
} || '' }
83 sub columns
{ shift-
>{columns
} || [] }
84 sub results
{ shift-
>{results
} }
89 $self->stream($_) for @_;
94 sub stream
{ push @{$_[0]->results}, $_[1] }
100 App::Codeowners::Formatter::CSV
101 App::Codeowners::Formatter::JSON
102 App::Codeowners::Formatter::String
103 App::Codeowners::Formatter::TSV
104 App::Codeowners::Formatter::Table
105 App::Codeowners::Formatter::YAML
119 App::Codeowners::Formatter - Base class for formatting codeowners output
127 my $formatter = App::Codeowners::Formatter->new(handle => *STDOUT);
128 $formatter->add_result($_) for @results;
132 This is a base class for formatters. A formatter is a class that takes data records, stringifies
133 them, and prints them to an IO handle.
135 This class is mostly abstract, though it is also usable as a null formatter where results are simply
136 discarded if it is instantiated directly. These other formatters do more interesting things:
142 L<App::Codeowners::Formatter::CSV>
146 L<App::Codeowners::Formatter::String>
150 L<App::Codeowners::Formatter::JSON>
154 L<App::Codeowners::Formatter::TSV>
158 L<App::Codeowners::Formatter::Table>
162 L<App::Codeowners::Formatter::YAML>
170 Get the IO handle associated with a formatter.
174 Get the format string, which may be used to customize the formatting.
178 Get an arrayref of column headings.
182 Get an arrayref of all the results that have been provided to the formatter using L</add_result> but
183 have not yet been formatted.
189 $formatter = App::Codeowners::Formatter->new;
190 $formatter = App::Codeowners::Formatter->new(%attributes);
192 Construct a new formatter.
196 Destructor calls L</finish>.
200 $formatter->add_result($result);
202 Provide an additional lint result to be formatted.
208 Begin formatting results. Called before any results are passed to the L</stream> method.
210 This method may print a header to the L</handle>. This method is used by subclasses and should
211 typically not be called explicitly.
215 $formatter->stream(\@result, ...);
219 This method is expected to print a string representation of the result to the L</handle>. This
220 method is used by subclasses and should typically not called be called explicitly.
222 The default implementation simply stores the L</results> so they will be available to L</finish>.
228 End formatting results. Called after all results are passed to the L</stream> method.
230 This method may print a footer to the L</handle>. This method is used by subclasses and should
231 typically not be called explicitly.
235 @formatters = App::Codeowners::Formatter->formatters;
237 Get a list of package names of potential formatters within the C<App::Codeowners::Formatter>
242 Please report any bugs or feature requests on the bugtracker website
243 L<https://github.com/chazmcgarvey/git-codeowners/issues>
245 When submitting a bug or request, please include a test-file or a
246 patch to an existing test-file that illustrates the bug or desired
251 Charles McGarvey <chazmcgarvey@brokenzipper.com>
253 =head1 COPYRIGHT AND LICENSE
255 This software is copyright (c) 2019 by Charles McGarvey.
257 This is free software; you can redistribute it and/or modify it under
258 the same terms as the Perl 5 programming language system itself.
This page took 0.047461 seconds and 4 git commands to generate.