UserAgent/Base/Dumper.pm

filter: Statementstmt 21.2% 14 / 66 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 40.0% 4 / 10 Podpod 100% 1 / 1 totaltotal 17.2% 19 / 110 CC 19 SCAR 43.2
CC
19
Cov
15%
_dumper_dumper
156.0
_dump_to_struct
30.0
dumper
20.0
CRAP 75.4
« UserAgent/Base/Parsers.pm ↑ Summary UserAgent/Base/IS.pm »
1 package Parse::HTTP::UserAgent::Base::Dumper;
2 4 $Parse::HTTP::UserAgent::Base::Dumper::VERSION = '0.43';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Parse::HTTP::UserAgent::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub dumper {
Subroutine dumper: not called CC=4 SCAR=30.0
Pod documented
9 0 my($self, @args) = @_;
10 0 ▶ my %opt = @args % 2 ? () : (
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 0 0 0
11 type => 'dumper',
12 format => 'none',
13 interpret => 0,
14 @args
15 );
16 0 my $meth = '_dumper_' . lc $opt{type};
17 0 ▶ croak "Don't know how to dump with $opt{type}" if ! $self->can( $meth );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($meth) 0 0 0
18 0 my $buf = $self->$meth( \%opt );
19 0 ▶ return $buf if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
20 0 my $pok = print $buf ."\n";
21 0 return;
22 }
23  
24 0 ▶sub _dump_to_struct {
Subroutine _dump_to_struct: not called CC=5 SCAR=34.0
25 0 my %struct = shift->as_hash;
26 0 ▶ $struct{$_} ||= [] for qw( dotnet mozilla extras tk );
Condition0%0/2
$struct{$_} ||= []
l!l
00
MC/DC0%0/1
$struct{$_} ||= []
$struct{$_}
Truth table0%0/2
A
A= $struct{$_}
Aresult
11
00
27 0 ▶ $struct{$_} ||= 0 for qw( unknown );
Condition0%0/2
$struct{$_} ||= 0
l!l
00
MC/DC0%0/1
$struct{$_} ||= 0
$struct{$_}
Truth table0%0/2
A
A= $struct{$_}
Aresult
11
00
28 0 return \%struct;
29 }
30  
31 0 ▶sub _dumper_json {
Subroutine _dumper_json: not called CC=1 SCAR=6.9
32 0 my $self = shift;
33 0 my $opt = shift;
34 0 require JSON;
35 return JSON::to_json(
36 $self->_dump_to_struct,
37 0 { pretty => $opt->{format} eq 'pretty' }
38 );
39 }
40  
41 0 ▶sub _dumper_xml {
Subroutine _dumper_xml: not called CC=1 SCAR=6.9
42 0 my $self = shift;
43 0 my $opt = shift;
44 0 require XML::Simple;
45 return XML::Simple::XMLout(
46 $self->_dump_to_struct,
47 RootName => 'ua',
48 0 NoIndent => $opt->{format} ne 'pretty',
49 );
50 }
51  
52 0 ▶sub _dumper_yaml {
Subroutine _dumper_yaml: not called CC=1 SCAR=6.9
53 0 my $self = shift;
54 0 my $opt = shift;
55 0 require YAML;
56 0 return YAML::Dump( $self->_dump_to_struct );
57 }
58  
59 0 ▶sub _dumper_dumper {
Subroutine _dumper_dumper: not called CC=12 SCAR=50.5
60 # yeah, I know. Fugly code here
61 0 my $self = shift;
62 0 my $opt = shift;
63 0 ▶ my @ids = $opt->{args} ? @{ $opt->{args} } : $self->_object_ids;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'args'} ? : 0 0 0
64 0 ▶ my $args = $opt->{args} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'args'} ? : 0 0 0
65 0 my $max = 0;
66 0 ▶ map { $max = length $_ if length $_ > $max; } @ids;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $max 0 0 0
67 0 my @titles = qw( FIELD VALUE );
68 0 my $buf = sprintf "%s%s%s\n%s%s%s\n",
69 $titles[0],
70 (q{ } x (2 + $max - length $titles[0])),
71 $titles[1],
72 q{-} x $max, q{ } x 2, q{-} x ($max*2);
73 0 require Data::Dumper;
74 0 my @buf;
75 0 foreach my $id ( @ids ) {
76 0 ▶ my $name = $args ? $id->{name} : $id;
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 0 0
77 0 ▶ my $val = $args ? $id->{value} : $self->[ $self->$id() ];
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 0 0
78 0 ▶ if ( $val && ref $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val and ref $val) 0 0 0
Condition0%0/3
$val and ref $val
!ll&&!rl&&r
000
MC/DC0%0/2
$val and ref $val
$val ref $val
Truth table0%0/3
A and B
A= $valB= ref $val
ABresult
0X0
100
111
79 0 my $d = Data::Dumper->new([$val]);
80 0 $d->Indent(0);
81 0 my $rv = $d->Dump;
82 0 $rv =~ s{ \$VAR1 \s+ = \s+ }{}xms;
83 0 $rv =~ s{ ; }{}xms;
84 0 ▶ $val = $rv eq '[]' ? q{} : $rv;
Branch: 1 branch
BranchTrueFalseTotal
$rv eq '[]' ? : 0 0 0
85 }
86 0 ▶ push @buf, [
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
87 $name,
88 (q{ } x (2 + $max - length $name)),
89 defined $val ? $val : q{}
90 ];
91 }
92 0 foreach my $row ( sort { lc $a->[0] cmp lc $b->[0] } @buf ) {
93 0 $buf .= sprintf "%s%s%s\n", @{ $row };
94 }
95 0 return $buf;
96 }
97  
98 4 1;
99  
100 __END__
« UserAgent/Base/Parsers.pm ↑ Summary UserAgent/Base/IS.pm »