| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | 1 | ▶ | use v5.20; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Text::Stencil; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # render_to_fh: stream large output to a file | ||||||||||
| 7 | 1 | my $s = Text::Stencil->new( | |||||||||
| 8 | header => "ID,Value\n", | ||||||||||
| 9 | row => '{0:int},{1:raw}', | ||||||||||
| 10 | separator => "\n", | ||||||||||
| 11 | footer => "\n", | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | 1 | my @rows = map { [$_, "val_$_"] } 1..100; | |||||||||
| 15 | 1 | $s->render_to_fh(\*STDOUT, \@rows); | |||||||||
| 16 | |||||||||||
| 17 | # render_cb: stream from a callback (e.g. database cursor) | ||||||||||
| 18 | 1 | say "\n--- render_cb ---"; | |||||||||
| 19 | 1 | my $i = 0; | |||||||||
| 20 | 1 | my $cb = Text::Stencil->new(row => '{0:int}: {1:raw}', separator => "\n"); | |||||||||
| 21 | 6 | ▶ | my $out = $cb->render_cb(sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 22 | 6 | ▶ | return undef if $i >= 5; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 5 | $i++; | |||||||||
| 24 | 5 | return [$i, "row $i"]; | |||||||||
| 25 | 1 | }); | |||||||||
| 26 | 1 | say $out; | |||||||||