TableDataRole/Munge/SerializeRef.pm

filter: Statementstmt 32.0% 17 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.7% 4 / 13 Podpod 12.5% 1 / 8 totaltotal 23.9% 22 / 92 CC 10 SCAR 30.3
CC
10
Cov
25%
new
56.0
get_next_item
12.0
get_next_row_hashref
6.0
CRAP 20.7
« TableDataRole/Munge/MungeColumns.pm ↑ Summary TableDataRole/Util/GetRowByPos.pm »
1 package TableDataRole::Munge::SerializeRef;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 1 our $DATE = '2024-05-14'; # DATE
11 1 our $DIST = 'TableDataRoles-Standard'; # DIST
12 1 our $VERSION = '0.025'; # VERSION
13  
14 1 with 'TableDataRole::Spec::Basic';
15  
16 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
17 0 require Module::Load::Util;
18  
19 0 my ($class, %args) = @_;
20  
21 0 ▶ my $tabledata = delete $args{tabledata} or die "Please specify 'tabledata' argument";
Branch: 1 branch
BranchTrueFalseTotal
my $tabledata = delete $args{"tabledata"} or die "Please specify 'tabledata' argument" 0 0 0
22 0 ▶ my $load = delete($args{load}) // 1;
Condition0%0/2
delete $args{"load"} // 1
l!l
00
MC/DC0%0/1
delete $args{"load"} // 1
delete $args{"load"}
Truth table0%0/2
A
A= delete $args{"load"}
Aresult
11
00
23 0 ▶ my $serializer = delete($args{serializer}) // 'json';
Condition0%0/2
delete $args{"serializer"} // "json"
l!l
00
MC/DC0%0/1
delete $args{"serializer"} // "json"
delete $args{"serializer"}
Truth table0%0/2
A
A= delete $args{"serializer"}
Aresult
11
00
24 0 ▶ die "Unknown argument(s): ". join(", ", sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if keys %args 0 0 0
25 if keys %args;
26  
27 0 my $td = Module::Load::Util::instantiate_class_with_optional_args(
28 {load=>$load, ns_prefix=>"TableData"}, $tabledata);
29  
30 0 ▶ if ($serializer eq 'json') {
Branch: 2 branches
BranchTrueFalseTotal
if ($serializer eq 'json') { } 0 0 0
elsif (ref $serializer ne 'CODE') { } 0 0 0
31 0 require JSON::MaybeXS;
32 0 ▶ $serializer = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 JSON::MaybeXS::encode_json($_[0]);
34 0 };
35 } elsif (ref($serializer) ne 'CODE') {
36 0 die "Invalid value for serializer '$serializer': please supply a coderef or 'json'";
37 }
38  
39 bless {
40 0 tabledata => $tabledata,
41 td => $td,
42 pos => 0,
43 serializer => $serializer,
44 }, $class;
45 }
46  
47 0 ▶sub get_column_count {
Subroutine get_column_count: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my $self = shift;
49 0 $self->{td}->get_column_count;
50 }
51  
52 0 ▶sub get_column_names {
Subroutine get_column_names: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my $self = shift;
54 0 $self->{td}->get_column_names;
55 }
56  
57 0 ▶sub has_next_item {
Subroutine has_next_item: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my $self = shift;
59 0 $self->{td}->has_next_item;
60 }
61  
62 0 ▶sub get_next_item {
Subroutine get_next_item: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my $self = shift;
64 0 my $row = $self->{td}->get_next_item;
65 0 for (@$row) {
66 0 ▶ if (ref $_) { $_ = $self->{serializer}->($_) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) 0 0 0
67 }
68 0 $row;
69 }
70  
71 0 ▶sub get_next_row_hashref {
Subroutine get_next_row_hashref: not called CC=2 SCAR=17.9
Pod undocumented
72 0 my $self = shift;
73 0 my $row = $self->get_next_item;
74 0 ▶ unless ($self->{_column_names}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_column_names"}) 0 0 0
75 0 $self->{_column_names} = $self->{td}->get_column_names;
76 }
77 0 +{ map {($self->{_column_names}->[$_] => $row->[$_])} 0..$#{$row} };
78 }
79  
80 0 ▶sub get_iterator_pos {
Subroutine get_iterator_pos: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my $self = shift;
82 0 $self->{td}->get_iterator_pos;
83 }
84  
85 0 ▶sub reset_iterator {
Subroutine reset_iterator: not called CC=1 SCAR=6.9
Pod undocumented
86 0 my $self = shift;
87 0 $self->{td}->reset_iterator;
88 }
89  
90 1 1;
91 # ABSTRACT: Serialize references in columns
92  
93 __END__
« TableDataRole/Munge/MungeColumns.pm ↑ Summary TableDataRole/Util/GetRowByPos.pm »