| 1 | |||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Data::Dumper::Again; | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.01'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | # for docs, look for F<Again.pod> | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | ▶ | use Data::Dumper (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 5 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 5 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 5 | __PACKAGE__->mk_accessors(qw(ddumper)); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # the instance variables | ||||||||||||||||||||
| 19 | # ddumper - the Data::Dumper inner object | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 22 | 5 | my $proto = shift; | |||||||||||||||||||
| 23 | 5 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 24 | 5 | my $obj = bless {}, $class; | |||||||||||||||||||
| 25 | 5 | return $obj->_init(@_); | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 5 | ▶ | sub _init { | ||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 29 | 5 | my $self = shift; | |||||||||||||||||||
| 30 | 5 | my %args = @_; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 5 | my $dumper = Data::Dumper->new([]); | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 5 | ▶ | while (my ($k, $v) = each %args) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 2 | my $p = "\u$k"; # turn into a method name | |||||||||||||||||||
| 36 | 2 | ▶ | if ($dumper->can($p)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | #print "invoke $p($v)\n"; # XXX debug for devel | ||||||||||||||||||||
| 38 | 2 | $dumper->$p($v); | |||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||
| 40 | 0 | carp "unknown constructor parameter '$k'"; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | 5 | $self->ddumper($dumper); | |||||||||||||||||||
| 44 | 5 | return $self; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 2 | ▶ | sub guts { | ||||||||||||||||||
|
Subroutine
guts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 48 | 2 | return shift->ddumper; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # $vname = $self->_varname($wantarray); | ||||||||||||||||||||
| 52 | 5 | ▶ | sub _varname { | ||||||||||||||||||
|
Subroutine
_varname: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 53 | 5 | my $self = shift; | |||||||||||||||||||
| 54 | 5 | my $wantarray = shift; | |||||||||||||||||||
| 55 | 5 | my $varname = $self->ddumper->Varname; | |||||||||||||||||||
| 56 | 5 | ▶ | return ( $wantarray ? '*' : '$' ) . $varname; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # $s = $self->_raw_dump(\@values, \@names); | ||||||||||||||||||||
| 60 | 6 | ▶ | sub _raw_dump { | ||||||||||||||||||
|
Subroutine
_raw_dump: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 6 | my $self = shift; | |||||||||||||||||||
| 62 | 6 | my $values_ref = shift; | |||||||||||||||||||
| 63 | 6 | my $names_ref = shift; | |||||||||||||||||||
| 64 | 6 | $self->ddumper->Reset; # forget previous invocations | |||||||||||||||||||
| 65 | 6 | $self->ddumper->Values( $values_ref ); | |||||||||||||||||||
| 66 | 6 | $self->ddumper->Names( $names_ref ); | |||||||||||||||||||
| 67 | 6 | return $self->ddumper->Dump; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 5 | ▶ | sub dump { | ||||||||||||||||||
|
Subroutine
dump: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 71 | 5 | my $self = shift; | |||||||||||||||||||
| 72 | 5 | my $wantarray = @_ != 1; | |||||||||||||||||||
| 73 | 5 | ▶ | my @values = ( $wantarray ? \@_ : shift ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 5 | my @names = ( $self->_varname($wantarray) ); | |||||||||||||||||||
| 75 | 5 | return $self->_raw_dump(\@values, \@names); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | sub dump_scalar { | ||||||||||||||||||
|
Subroutine
dump_scalar: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||
| 80 | 0 | my @values = ( shift ); | |||||||||||||||||||
| 81 | 0 | my @names = ( $self->_varname(0) ); # wantarray => 0 | |||||||||||||||||||
| 82 | 0 | return $self->_raw_dump(\@values, \@names); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub dump_list { | ||||||||||||||||||
|
Subroutine
dump_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||
| 87 | 0 | my @values = ( \@_ ); | |||||||||||||||||||
| 88 | 0 | my @names = ( $self->_varname(1) ); # wantarray => 1 | |||||||||||||||||||
| 89 | 0 | return $self->_raw_dump(\@values, \@names); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | ▶ | sub dump_named { | ||||||||||||||||||
|
Subroutine
dump_named: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 93 | 1 | my $self = shift; | |||||||||||||||||||
| 94 | 1 | my @pairs = @_; | |||||||||||||||||||
| 95 | 1 | my (@names, @values); | |||||||||||||||||||
| 96 | 1 | ▶ | while (@pairs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 1 | my ($n, $v) = splice @pairs, 0, 2; | |||||||||||||||||||
| 98 | 1 | push @names, $n; | |||||||||||||||||||
| 99 | 1 | push @values, $v; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | 1 | return $self->_raw_dump(\@values, \@names); | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | # the following AUTOLOAD sub implements set_* | ||||||||||||||||||||
| 105 | # and get_* methods | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 5 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||
| 111 | 0 | my $method = $AUTOLOAD; | |||||||||||||||||||
| 112 | 0 | $method =~ s/.*:://; | |||||||||||||||||||
| 113 | 0 | ▶ | if ($method =~ /[gs]et_(\w+)/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 0 | my $prop = "\u$1"; | |||||||||||||||||||
| 115 | 0 | ▶ | if ($self->ddumper->can($prop)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 0 | return $self->ddumper->$prop(@_); | |||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||
| 118 | 0 | croak "unknown getter/setter method '$method'"; # XXX | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | 0 | croak "unknown method '$method'"; # XXX | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | # this avoids invoking AUTOLOAD on destruction | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 5 | 1; | |||||||||||||||||||
| 129 | |||||||||||||||||||||