blib/lib/Data/Record/Serialize/Encode/table.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 5 totaltotal 89.6% 69 / 77 CC 5 SCAR 7.2
CC
5
Cov
100%
finalize
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
↑ Summary
1 package Data::Record::Serialize::Encode::table;
2  
3 # ABSTRACT: encode records as a formatted table and output it
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.02';
9  
10 2 ▶use Types::Standard qw( ArrayRef Bool Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Types::Common::Numeric qw( PositiveInt );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Term::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 with 'Data::Record::Serialize::Role::Sink::Stream';
19  
20 2 ▶use constant BOOLS => qw( allow_overflow auto_columns collapse mark_tail sanitize show_header );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 has _rows => (
23 is => 'ro',
24 init_arg => undef,
25 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 2 );
27  
28 2 has [ 'max_width', 'pad' ] => (
29 is => 'ro',
30 isa => PositiveInt,
31 predicate => 1,
32 );
33  
34 2 has [BOOLS] => (
35 is => 'ro',
36 isa => Bool,
37 predicate => 1,
38 );
39  
40 has no_collapse => (
41 is => 'ro',
42 isa => ArrayRef [Str],
43 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 predicate => 1,
45 );
46  
47 2 has _closed => (
48 is => 'rwp',
49 init_arg => undef,
50 default => 1,
51 );
52  
53 3 ▶sub send { ## no critic( BuiltinHomonyms )
Subroutine send: called CC=1 SCAR=0.0
Pod undocumented
54 3 my $self = shift;
55 3 my $rec = shift;
56 3 push @{ $self->_rows }, [ @{$rec}{ @{ $self->output_fields } } ];
57 3 $self->_set__closed( 0 );
58 }
59  
60 # we've overridden send(), so don't need encode(), but the Encode role
61 # does, so here's one:
62 0 ▶sub encode { }
Subroutine encode: not called CC=1 SCAR=0.0
Pod undocumented
63  
64 0 ▶sub print { } ## no critic( BuiltinHomonyms )
Subroutine print: not called CC=1 SCAR=0.0
Pod undocumented
65 0 ▶sub say { } ## no critic( BuiltinHomonyms )
Subroutine say: not called CC=1 SCAR=0.0
Pod undocumented
66  
67 5 ▶sub finalize {
Subroutine finalize: called CC=5 SCAR=16.1
Pod undocumented
68 5 my $self = shift;
69 5 ▶ return if $self->_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_closed 3 2 5
70  
71 2 my %options;
72 2 for my $option ( BOOLS, qw( max_width pad no_collapse ) ) {
73 18 my $predicate = "has_$option";
74 18 ▶ $options{$option} = $self->$option if $self->$predicate();
Branch: 1 branch
BranchTrueFalseTotal
if $self->$predicate 3 15 18
75 }
76  
77 2 my $table = Term::Table->new(
78 %options,
79 header => $self->output_fields,
80 rows => $self->_rows,
81 );
82  
83 2 my $fh = $self->fh;
84 2 $fh->print( "$_\n" ) for $table->render;
85 2 $self->_set__closed( 1 );
86 }
87  
88 2 with 'Data::Record::Serialize::Role::Encode';
89 2 with 'Data::Record::Serialize::Role::Sink';
90  
91 2 1;
92  
93 #
94 # This file is part of Data-Record-Serialize-Encode-table
95 #
96 # This software is Copyright (c) 2026 by Smithsonian Astrophysical Observatory.
97 #
98 # This is free software, licensed under:
99 #
100 # The GNU General Public License, Version 3, June 2007
101 #
102  
103 __END__
↑ Summary