| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 18 | 0 | my $buf = $self->$meth( \%opt ); | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | return $buf if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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{$_} ||= []
MC/DC0%0/1
$struct{$_} ||= []
$struct{$_}
Truth table0%0/2
A
A= $struct{$_}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $struct{$_} ||= 0 for qw( unknown ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$struct{$_} ||= 0
MC/DC0%0/1
$struct{$_} ||= 0
$struct{$_}
Truth table0%0/2
A
A= $struct{$_}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $args = $opt->{args} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | my $max = 0; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | map { $max = length $_ if length $_ > $max; } @ids; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $val = $args ? $id->{value} : $self->[ $self->$id() ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( $val && ref $val ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val and ref $val
MC/DC0%0/2
$val and ref $val
$val
ref $val
Truth table0%0/3
A and B
A= $valB= ref $val
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | push @buf, [ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||