]> Dogcows Code - chaz/git-codeowners/blobdiff - lib/App/Codeowners/Formatter/Table.pm
refactor formatters
[chaz/git-codeowners] / lib / App / Codeowners / Formatter / Table.pm
diff --git a/lib/App/Codeowners/Formatter/Table.pm b/lib/App/Codeowners/Formatter/Table.pm
new file mode 100644 (file)
index 0000000..1f9373e
--- /dev/null
@@ -0,0 +1,34 @@
+package App::Codeowners::Formatter::Table;
+# ABSTRACT: Format codeowners output as a table
+
+=head1 DESCRIPTION
+
+This is a L<App::Codeowners::Formatter> that formats output using L<Text::Table::Any>.
+
+=cut
+
+use warnings;
+use strict;
+
+our $VERSION = '9999.999'; # VERSION
+
+use parent 'App::Codeowners::Formatter';
+
+use App::Codeowners::Util qw(stringify);
+use Encode qw(encode);
+
+sub finish {
+    my $self    = shift;
+    my $results = shift;
+
+    eval { require Text::Table::Any } or die "Missing dependency: Text::Table::Any\n";
+
+    my $table = Text::Table::Any::table(
+        header_row  => 1,
+        rows        => [$self->columns, map { [map { stringify($_) } @$_] } @$results],
+        backend     => $ENV{PERL_TEXT_TABLE},
+    );
+    print { $self->handle } encode('UTF-8', $table);
+}
+
+1;
This page took 0.026539 seconds and 4 git commands to generate.