我不知道任何DBIC 漂亮的打印模塊,但它很容易從任何無數的文本,HTML或其他類型的CPAN表格輸出模塊實現。
下面是一個使用Text::Table
use 5.012;
use warnings;
use List::MoreUtils 'zip';
use Text::Table;
# my database with Album schema from DBIx::Class::Manual::Intro
use MySchema;
my $db = MySchema->connect("DBI:SQLite:myschema_db");
my $album = $db->resultset('Album');
# get column names for the Album table
my @cols = $album->result_source->columns;
# create header with these column names
my $table = Text::Table->new(header(@cols));
# add each Album row to table output
while (my $cd = $album->next) {
$table->add(map { $cd->get_column($_) } @cols);
}
print $table; # => tabular text output
# adds | separator between header labels
sub header {
my @sep = (\' | ') x @_;
zip @_, @sep;
}
這與輸出我的測試數據下面我快速的工作例如:
albumid | artist | title | rank |
1 | Lou Reed | Transformer | |
2 | Lou Reed | Berlin | |
3 | David Bowie | Ziggy Stardust | |
4 | Japan | Tin Drum | |
/I3az/