File: formatter.t

package info (click to toggle)
libdbix-runsql-perl 0.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: perl: 825; sql: 26; makefile: 10
file content (67 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!perl -w
use strict;
use Test::More;

use DBIx::RunSQL;

my $can_run = eval {
    require Text::Table;
    require DBD::SQLite;
    1
};

if (not $can_run) {
    plan skip_all => "Test prerequisite modules not installed: $@";
    exit;
};

plan tests => 1;

my $sql= <<'SQL';
    create table foo (
        name varchar(64)
      , age decimal(4)
    );
    insert into foo (name,age) values ('bar',100);
    insert into foo (name,age) values ('baz',1);
SQL

my $test_dbh = DBIx::RunSQL->create(
    dsn     => 'dbi:SQLite:dbname=:memory:',
    sql     => \$sql,
);

my $sth= $test_dbh->prepare(<<'SQL');
    select * from foo order by name;
SQL
$sth->execute;
my $result= DBIx::RunSQL->format_results( sth => $sth, formatter => 'Text::Table::JIRA' );
is_deeply [split /\r?\n/, $result],
['||name||age||',
 '| bar | 100| ',
 '| baz |   1| ',
]
;

package Text::Table::JIRA;
use strict;
our @ISA;
require Text::Table;
BEGIN {
    @ISA = 'Text::Table';
}

sub new {
    my( $class, @headers ) = @_;

	my $sep = {
	    is_sep => 1,
		title => '||',
		body  => '| ',
	};

	@headers = ($sep, map {
	    $_, $sep,
	} @headers);
	$class->SUPER::new( @headers )
}