File Coverage

blib/lib/DBIx/DataModel/Schema/ResultAs/File_tabular.pm
Criterion Covered Total %
statement 37 37 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 1 2 50.0
total 48 52 92.3


line stmt bran cond sub pod time code
1             #----------------------------------------------------------------------
2             package DBIx::DataModel::Schema::ResultAs::File_tabular;
3             #----------------------------------------------------------------------
4 1     1   590 use warnings;
  1         3  
  1         39  
5 1     1   7 use strict;
  1         2  
  1         26  
6 1     1   6 use Carp::Clan qw[^(DBIx::DataModel::|SQL::Abstract)];
  1         2  
  1         9  
7 1     1   111 use File::Tabular;
  1         3  
  1         25  
8              
9 1     1   5 use parent 'DBIx::DataModel::Schema::ResultAs';
  1         2  
  1         5  
10              
11 1     1   102 use namespace::clean;
  1         2  
  1         11  
12              
13             sub new {
14 1     1 0 3 my $class = shift;
15              
16 1         3 my $self = {ft_args => \@_};
17 1         4 return bless $self, $class;
18             }
19              
20              
21              
22             sub get_result {
23 1     1 1 3 my ($self, $statement) = @_;
24              
25 1         7 $statement->execute;
26 1         6 $statement->make_fast;
27              
28 1         4 my @headers = $statement->headers;
29 1         24 my @ft_args = @{$self->{ft_args}};
  1         8  
30 1 50 33     11 push @ft_args, {} unless @ft_args && ref $ft_args[1];
31              
32 1         4 $ft_args[-1]{headers} = [$statement->headers];
33 1         28 $ft_args[-1]{printHeaders} = 1;
34              
35 1         6 my $ft = File::Tabular->new(@ft_args);
36 1         381 my $n_rows = 0;
37 1         7 while (my $row = $statement->next) {
38 3         12 $ft->append($row);
39 3         285 $n_rows += 1;
40             }
41 1         6 $statement->finish;
42              
43 1         58 return $n_rows;
44             }
45              
46              
47             1;
48              
49              
50             __END__