| 1 | package Data::Dumper::AutoEncode; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Scalar::Util qw(blessed refaddr); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use B; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Data::Dumper; # Dumper | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '1.00'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | our $ENCODING = ''; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | our $CHECK_ALREADY_ENCODED = 0; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | our $DO_NOT_PROCESS_NUMERIC_VALUE = 1; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | our $FLAG_STR = ''; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | our $BEFORE_HOOK; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | our $AFTER_HOOK; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | my %args = map { $_ => 1 } @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | if (delete $args{'-dumper'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | *{__PACKAGE__."::Dumper"} = *{__PACKAGE__."::eDumper"}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my $export_all = !!(scalar(keys %args) == 0); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | my $pkg = caller; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | for my $f (qw/ Dumper eDumper /) { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | ▶ | if ( $export_all || (exists $args{$f} && $args{$f}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$export_all or exists $args{$f} and $args{$f}
exists $args{$f} and $args{$f}
MC/DC66%2/3
$export_all or exists $args{$f} and $args{$f}
$export_all
exists $args{$f}
$args{$f}
Truth table75%3/4
A or B and C
A= $export_allB= exists $args{$f}C= $args{$f}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | *{"${pkg}::${f}"} = \&{$f}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | sub _dump { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | my $d = Data::Dumper->new(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | return $d->Dump; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | ▶ | sub eDumper { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eDumper: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 13 | ▶ | push @args, encode($ENCODING || 'utf8', $arg); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Data::Dumper::AutoEncode::ENCODING || 'utf8'
MC/DC100%1/1
$Data::Dumper::AutoEncode::ENCODING || 'utf8'
$Data::Dumper::AutoEncode::ENCODING
Truth table100%2/2
A
A= $Data::Dumper::AutoEncode::ENCODING
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 12 | _dump(@args); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my ($encoding, $stuff, $check) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 13 | ▶ | $encoding = Encode::find_encoding($encoding) | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&Encode::find_encoding($encoding) || Carp::croak("unknown encoding '${encoding}'")
MC/DC0%0/1
&Encode::find_encoding($encoding) || Carp::croak("unknown encoding '${encoding}'")
&Encode::find_encoding($encoding)
Truth table50%1/2
A
A= &Encode::find_encoding($encoding)
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | || Carp::croak("unknown encoding '$encoding'"); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ▶ | $check ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$check ||= 0
MC/DC0%0/1
$check ||= 0
$check
Truth table50%1/2
A
A= $check
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | ▶ | _apply(sub { $encoding->encode($_[0], $check) }, {}, $stuff); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # copied from Data::Recursive::Encode | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | ▶ | sub _apply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply: called CC=11 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 15 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 15 | my $seen = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 15 | my @retval; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 15 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 17 | ▶ | if(my $ref = ref $arg){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my $refaddr = refaddr($arg); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my $proto; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if(defined($proto = $seen->{$refaddr})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | # noop | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | elsif($ref eq 'ARRAY'){ | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $proto = $seen->{$refaddr} = []; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | @{$proto} = _apply($code, $seen, @{$arg}); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | elsif($ref eq 'HASH'){ | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | $proto = $seen->{$refaddr} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | %{$proto} = _apply($code, $seen, %{$arg}); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ▶ | elsif($ref eq 'REF' or $ref eq 'SCALAR'){ | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ref eq "REF" or $ref eq "SCALAR"
MC/DC0%0/2
$ref eq "REF" or $ref eq "SCALAR"
$ref eq "REF"
$ref eq "SCALAR"
Truth table0%0/3
A or B
A= $ref eq "REF"B= $ref eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $proto = $seen->{$refaddr} = \do{ my $scalar }; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ${$proto} = _apply($code, $seen, ${$arg}); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | else{ # CODE, GLOB, IO, LVALUE etc. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $proto = $seen->{$refaddr} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | push @retval, $proto; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 15 | ▶ | if (_can_exec($arg)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | ▶ | push @retval, $FLAG_STR ? $FLAG_STR . _exec($code, $arg) : _exec($code, $arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | push @retval, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 15 | ▶ | return wantarray ? @retval : $retval[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | sub _exec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | my ($code, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | ▶ | if (ref $BEFORE_HOOK eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $arg = $BEFORE_HOOK->($arg); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | my $result = $code->($arg); | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | if (ref $AFTER_HOOK eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return $AFTER_HOOK->($result); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | # copied from Data::Recursive::Encode | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 15 | ▶ | sub _is_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_number: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 15 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 15 | ▶ | return 0 unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 15 | my $b_obj = B::svref_2object(\$value); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 15 | my $flags = $b_obj->FLAGS; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 15 | ▶ | return $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flags & 12288 and not $flags & 16384
MC/DC50%1/2
$flags & 12288 and not $flags & 16384
$flags & 12288
not $flags & 16384
Truth table66%2/3
A and not(B)
A= $flags & 12288B= not $flags & 16384
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 15 | ▶ | sub _can_exec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_can_exec: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 15 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 15 | ▶ | return unless defined($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 15 | ▶ | return if $DO_NOT_PROCESS_NUMERIC_VALUE && _is_number($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Data::Dumper::AutoEncode::DO_NOT_PROCESS_NUMERIC_VALUE and _is_number($arg)
MC/DC50%1/2
$Data::Dumper::AutoEncode::DO_NOT_PROCESS_NUMERIC_VALUE and _is_number($arg)
$Data::Dumper::AutoEncode::DO_NOT_PROCESS_NUMERIC_VALUE
_is_number($arg)
Truth table66%2/3
A and B
A= $Data::Dumper::AutoEncode::DO_NOT_PROCESS_NUMERIC_VALUEB= _is_number($arg)
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 14 | ▶ | return 1 if Encode::is_utf8($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | return 1 if !$CHECK_ALREADY_ENCODED && !Encode::is_utf8($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Data::Dumper::AutoEncode::CHECK_ALREADY_ENCODED or &Encode::is_utf8($arg)
MC/DC50%1/2
$Data::Dumper::AutoEncode::CHECK_ALREADY_ENCODED or &Encode::is_utf8($arg)
$Data::Dumper::AutoEncode::CHECK_ALREADY_ENCODED
&Encode::is_utf8($arg)
Truth table66%2/3
A or B
A= $Data::Dumper::AutoEncode::CHECK_ALREADY_ENCODEDB= &Encode::is_utf8($arg)
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||||||||||||||||