| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Exception::Reporter::Dumper::YAML; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: a dumper to turn any scalar value into a plaintext YAML record | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | $Exception::Reporter::Dumper::YAML::VERSION = '0.014'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Exception::Reporter::Dumper'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use YAML::XS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | sub _ident_from { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | my ($self, $str, $x) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ident_from: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | $str =~ s/\A\n+//; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ($str) = split /\n/, $str; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | unless (defined $str and length $str and $str =~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $str and length $str and $str =~ /\S/
defined $str and length $str
MC/DC0%0/3
defined $str and length $str and $str =~ /\S/
defined $str
length $str
$str =~ /\S/
Truth table25%1/4
A and B and C
A= defined $strB= length $strC= $str =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $str = sprintf "<<unknown%s>>", $x ? ' ($x)' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | sub dump { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | my ($self, $value, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=5 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | my $basename = $arg->{basename} || 'dump'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg->{'basename'} || 'dump'
MC/DC0%0/1
$arg->{'basename'} || 'dump'
$arg->{'basename'}
Truth table50%1/2
A
A= $arg->{'basename'}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | my ($dump, $error) = try { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | (YAML::XS::Dump($value), undef); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | } catch { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | (undef, $_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | if (defined $dump) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | my $ident = ref $value ? (try { "$value" } catch { "<unknown>" }) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | : defined $value ? "$value" # quotes in case of glob, vstr, etc. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | : "(undef)"; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | $ident = $self->_ident_from($ident); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | filename => "$basename.yaml", | |||||||||||||||||||||||||||||||||||||||||
| 43 | mimetype => 'text/plain', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | body => $dump, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ident => $ident, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $string = try { "$value" } catch { "value could not stringify: $_" }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $ident = $self->_ident_from($string); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | filename => "$basename.txt", | |||||||||||||||||||||||||||||||||||||||||
| 53 | mimetype => 'text/plain', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | body => <<EOB, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||