Serialize/Encode/ddump.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 1 totaltotal 93.4% 57 / 61 CC 5 SCAR 4.6
CC
5
Cov
93%
__ANON__
3.0
__ANON__
2.1
__ANON__
2.1
CRAP 1.6
« Serialize/Encode/yaml.pm ↑ Summary Serialize/Sink/stream.pm »
1 package Data::Record::Serialize::Encode::ddump;
2  
3 # ABSTRACT: encoded a record using Data::Dumper
4  
5 7 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our $VERSION = '2.05';
9  
10 7 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Data::Record::Serialize::Error { errors => ['::parameter'] }, -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 29 ▶sub _needs_eol { 1 }
Subroutine _needs_eol: called CC=1 SCAR=0.0
16  
17  
18  
19  
20  
21  
22  
23  
24 has ddump => (
25 is => 'lazy',
26 19 ▶ isa => sub { Scalar::Util::blessed $_[0] && $_[0]->isa( 'Data::Dumper' ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->isa("Data::Dumper") 19 0 19
27 8 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build_ddump: called CC=1 SCAR=0.0
28 8 Data::Dumper->new( [] );
29 },
30 7 );
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44 has dd_config => (
45 is => 'ro',
46 19 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
47 19 ▶ ref $_[0] eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "HASH" or error("::parameter", "'config' parameter must be a hashref'") 19 0 19
48 or error( '::parameter' => q{'config' parameter must be a hashref'} );
49 },
50 13 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 7 );
52  
53  
54  
55  
56  
57  
58 29 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod undocumented
59 29 my $self = shift;
60 29 $self->ddump->Values( \@_ )->Dump . q{,};
61 }
62  
63 19 ▶around BUILD => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
64 19 my ( $orig, $self ) = ( shift, shift );
65  
66 19 $orig->( $self, @_ );
67  
68 19 my $ddump = $self->ddump;
69 my %config = (
70 19 %{ $self->dd_config },
71 Terse => 1,
72 Trailingcomma => 1,
73 );
74  
75 19 for my $mth ( keys %config ) {
76 56 ▶ my $code = $ddump->can( $mth )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $ddump->can($mth) or error("::parameter", "$mth is not a Data::Dumper configuration variable") 56 0 56
77 or error( '::parameter', "$mth is not a Data::Dumper configuration variable" );
78 56 $code->( $ddump, $config{$mth} );
79 }
80 19 return;
81 7 };
82  
83  
84  
85  
86  
87  
88  
89  
90 7 with 'Data::Record::Serialize::Role::Encode';
91  
92 7 1;
93  
94 #
95 # This file is part of Data-Record-Serialize
96 #
97 # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
98 #
99 # This is free software, licensed under:
100 #
101 # The GNU General Public License, Version 3, June 2007
102 #
103  
104 __END__
« Serialize/Encode/yaml.pm ↑ Summary Serialize/Sink/stream.pm »