eg/streaming.pl

filter: Statementstmt 100% 20 / 20 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 26 / 26 CC 2 SCAR 3.4
CC
2
Cov
100%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« blib/lib/Text/Stencil.pm ↑ Summary XS.xs »
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
BranchTrueFalseTotal
if $i >= 5 1 5 6
23 5 $i++;
24 5 return [$i, "row $i"];
25 1 });
26 1 say $out;
« blib/lib/Text/Stencil.pm ↑ Summary XS.xs »