| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Parse::HTTP::UserAgent::Base::Dumper; | 
| 2 |  |  |  |  |  |  | $Parse::HTTP::UserAgent::Base::Dumper::VERSION = '0.42'; | 
| 3 | 2 |  |  | 2 |  | 16 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 4 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 88 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use Carp qw( croak ); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 105 |  | 
| 6 | 2 |  |  | 2 |  | 11 | use Parse::HTTP::UserAgent::Constants qw(:all); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1775 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub dumper { | 
| 9 | 281 |  |  | 281 | 1 | 1266 | my($self, @args) = @_; | 
| 10 | 281 | 50 |  |  |  | 1094 | my %opt = @args % 2 ? () : ( | 
| 11 |  |  |  |  |  |  | type      => 'dumper', | 
| 12 |  |  |  |  |  |  | format    => 'none', | 
| 13 |  |  |  |  |  |  | interpret => 0, | 
| 14 |  |  |  |  |  |  | @args | 
| 15 |  |  |  |  |  |  | ); | 
| 16 | 281 |  |  |  |  | 678 | my $meth = '_dumper_' . lc $opt{type}; | 
| 17 | 281 | 50 |  |  |  | 923 | croak "Don't know how to dump with $opt{type}" if ! $self->can( $meth ); | 
| 18 | 281 |  |  |  |  | 624 | my $buf = $self->$meth( \%opt ); | 
| 19 | 281 | 50 |  |  |  | 1638 | return $buf if defined wantarray; | 
| 20 | 0 |  |  |  |  | 0 | my $pok = print $buf ."\n"; | 
| 21 | 0 |  |  |  |  | 0 | return; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub _dump_to_struct { | 
| 25 | 0 |  |  | 0 |  | 0 | my %struct    = shift->as_hash; | 
| 26 | 0 |  | 0 |  |  | 0 | $struct{$_} ||= [] for qw( dotnet mozilla extras tk ); | 
| 27 | 0 |  | 0 |  |  | 0 | $struct{$_} ||= 0  for qw( unknown ); | 
| 28 | 0 |  |  |  |  | 0 | return \%struct; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub _dumper_json { | 
| 32 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 33 | 0 |  |  |  |  | 0 | my $opt  = shift; | 
| 34 | 0 |  |  |  |  | 0 | require JSON; | 
| 35 |  |  |  |  |  |  | return  JSON::to_json( | 
| 36 |  |  |  |  |  |  | $self->_dump_to_struct, | 
| 37 | 0 |  |  |  |  | 0 | { pretty => $opt->{format} eq 'pretty' } | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub _dumper_xml { | 
| 42 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 43 | 0 |  |  |  |  | 0 | my $opt  = shift; | 
| 44 | 0 |  |  |  |  | 0 | require XML::Simple; | 
| 45 |  |  |  |  |  |  | return  XML::Simple::XMLout( | 
| 46 |  |  |  |  |  |  | $self->_dump_to_struct, | 
| 47 |  |  |  |  |  |  | RootName => 'ua', | 
| 48 | 0 |  |  |  |  | 0 | NoIndent => $opt->{format} ne 'pretty', | 
| 49 |  |  |  |  |  |  | ); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub _dumper_yaml { | 
| 53 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 54 | 0 |  |  |  |  | 0 | my $opt  = shift; | 
| 55 | 0 |  |  |  |  | 0 | require YAML; | 
| 56 | 0 |  |  |  |  | 0 | return  YAML::Dump( $self->_dump_to_struct ); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub _dumper_dumper { | 
| 60 |  |  |  |  |  |  | # yeah, I know. Fugly code here | 
| 61 | 281 |  |  | 281 |  | 399 | my $self = shift; | 
| 62 | 281 |  |  |  |  | 327 | my $opt  = shift; | 
| 63 | 281 | 50 |  |  |  | 915 | my @ids  = $opt->{args} ?  @{ $opt->{args} } : $self->_object_ids; | 
|  | 0 |  |  |  |  | 0 |  | 
| 64 | 281 | 50 |  |  |  | 1572 | my $args = $opt->{args} ?                  1 : 0; | 
| 65 | 281 |  |  |  |  | 360 | my $max  = 0; | 
| 66 | 281 | 100 |  |  |  | 443 | map { $max = length $_ if length $_ > $max; } @ids; | 
|  | 6463 |  |  |  |  | 11764 |  | 
| 67 | 281 |  |  |  |  | 473 | my @titles = qw( FIELD VALUE ); | 
| 68 | 281 |  |  |  |  | 1436 | 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 | 281 |  |  |  |  | 1929 | require Data::Dumper; | 
| 74 | 281 |  |  |  |  | 6086 | my @buf; | 
| 75 | 281 |  |  |  |  | 493 | foreach my $id ( @ids ) { | 
| 76 | 6463 | 50 |  |  |  | 9634 | my $name = $args ? $id->{name} : $id; | 
| 77 | 6463 | 50 |  |  |  | 13948 | my $val  = $args ? $id->{value} : $self->[ $self->$id() ]; | 
| 78 | 6463 | 100 | 100 |  |  | 12984 | if ( $val && ref $val ) { | 
| 79 | 421 |  |  |  |  | 1273 | my $d = Data::Dumper->new([$val]); | 
| 80 | 421 |  |  |  |  | 9104 | $d->Indent(0); | 
| 81 | 421 |  |  |  |  | 4072 | my $rv = $d->Dump; | 
| 82 | 421 |  |  |  |  | 9153 | $rv =~ s{ \$VAR1 \s+ = \s+ }{}xms; | 
| 83 | 421 |  |  |  |  | 1080 | $rv =~ s{ ; }{}xms; | 
| 84 | 421 | 50 |  |  |  | 2356 | $val = $rv eq '[]' ? q{} : $rv; | 
| 85 |  |  |  |  |  |  | } | 
| 86 | 6463 | 100 |  |  |  | 17587 | push @buf, [ | 
| 87 |  |  |  |  |  |  | $name, | 
| 88 |  |  |  |  |  |  | (q{ } x (2 + $max - length $name)), | 
| 89 |  |  |  |  |  |  | defined $val ? $val : q{} | 
| 90 |  |  |  |  |  |  | ]; | 
| 91 |  |  |  |  |  |  | } | 
| 92 | 281 |  |  |  |  | 953 | foreach my $row ( sort { lc $a->[0] cmp lc $b->[0] } @buf ) { | 
|  | 21598 |  |  |  |  | 29578 |  | 
| 93 | 6463 |  |  |  |  | 7590 | $buf .= sprintf "%s%s%s\n", @{ $row }; | 
|  | 6463 |  |  |  |  | 11586 |  | 
| 94 |  |  |  |  |  |  | } | 
| 95 | 281 |  |  |  |  | 2198 | return $buf; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | 1; | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | __END__ |