AutoCRUD/View/Tsv.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 CC 1 SCAR 6.9
CC
1
Cov
0%
render
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::AutoCRUD::View::Tsv;
2
3 use 5.010;
4 use strict;
5 use warnings;
6
7 use Moose;
8 extends 'App::AutoCRUD::View';
9 use Encode qw/encode/;
10
11 use namespace::clean -except => 'meta';
12
13 sub render {
14 my ($self, $data, $context) = @_;
15
16 # ordered column names from colgroups
17 my @headers;
18 foreach my $colgroup (@{$data->{colgroups}}) {
19 my $cols = $colgroup->{columns};
20 push @headers, map {$_->{COLUMN_NAME}} @$cols;
21 }
22
23 # assemble header row and data rows
24 no warnings 'uninitialized';
25 my $str = join("\n", join("\t", @headers),
26 map {join("\t", @{$_}{@headers})} @{$data->{rows}});
27
28 # return Plack response
29 return [200, ['Content-type' => 'text/tab-separated-values; charset=utf-16'],
30 [encode("utf16", $str)] ];
31 }
32
33
34 1;
35
36
37 __END__