blib/lib/Astro/App/Satpass2/Format/Dump.pm

filter: Statementstmt 82.6% 38 / 46 Branchbran 45.0% 9 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 3 / 3 totaltotal 72.7% 56 / 77 CC 12 SCAR 18.6
CC
12
Cov
71%
dumper
10.5
_dump
6.0
new
3.1
CRAP 6.4
« blib/lib/Astro/App/Satpass2/Format/Template.pm ↑ Summary blib/lib/Astro/App/Satpass2/Copier.pm »
1 package Astro::App::Satpass2::Format::Dump;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use parent qw{ Astro::App::Satpass2::Format };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Astro::App::Satpass2::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 load_package
10 CODE_REF
11 @CARP_NOT
12 2 };
13  
14 2 our $VERSION = '0.059';
15  
16 2 my %dumper_hash = (
17 'YAML' => 'Dump',
18 'Data::Dumper' => 'Dumper',
19 'JSON' => 'to_json',
20 );
21  
22 {
23  
24 2 my $dumper_default;
25  
26 2 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
27 2 my ( $class, @args ) = @_;
28 2 my $self = $class->SUPER::new( @args );
29 2 ▶ if ( ! $self->dumper() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dumper) 2 0 2
30 2 ▶ if ( $dumper_default ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dumper_default) { } 0 2 2
31 0 $self->dumper( $dumper_default );
32 } else {
33 2 $self->dumper(
34 'YAML,Data::Dumper'
35 );
36 2 $dumper_default = $self->dumper();
37 }
38 }
39 2 return $self;
40 }
41  
42 }
43  
44 2 ▶sub dumper {
Subroutine dumper: called CC=9 SCAR=23.5
Pod documented
45 6 my ( $self, @args ) = @_;
46 6 ▶ @args or return $self->{+__PACKAGE__}{dumper};
Branch: 1 branch
BranchTrueFalseTotal
@args or return $self->{"Astro::App::Satpass2::Format::Dump"}{"dumper"} 2 4 6
47 2 my $val = shift @args;
48 2 my $ref = ref $val;
49 2 ▶ if ( ! $ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref) { } 2 0 2
elsif ('CODE' ne $ref) { } 0 0 0
50 2 foreach my $possible ( split qr{ , }smx, $val ) {
51 2 ▶ my $code = $dumper_hash{$possible} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $dumper_hash{$possible} or next 2 0 2
52 2 ▶ load_package( $possible ) or next;
Branch: 1 branch
BranchTrueFalseTotal
load_package($possible) or next 2 0 2
53 2 ▶ $code = $possible->can( $code ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$code = $possible->can($code) or next 2 0 2
54 2 $val = $code;
55 2 last;
56 }
57 2 ▶ ref $val
Branch: 1 branch
BranchTrueFalseTotal
ref $val or $self->wail("Unknown or unavailable dumper class '${val}'") 2 0 2
58 or $self->wail(
59 "Unknown or unavailable dumper class '$val'" );
60 } elsif ( CODE_REF ne $ref ) {
61 0 $self->wail(
62 'Dumper must be a code ref or the name of a known class' );
63 }
64 2 $self->{+__PACKAGE__}{dumper} = $val;
65 2 return $self;
66 }
67  
68 0 ▶sub _dump {
Subroutine _dump: not called CC=2 SCAR=17.9
69 0 my ( $self, $object ) = @_;
70 0 ▶ if ( defined $object ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object) { } 0 0 0
71 0 return $self->dumper()->( $object );
72 } else {
73 0 return '';
74 }
75 }
76  
77 0 ▶sub format : method { ## no critic (ProhibitBuiltInHomonyms)
Subroutine format: not called CC=1 SCAR=6.9
Pod documented
78 0 my ( $self, %data ) = @_;
79 0 return $self->_dump( \%data );
80 }
81  
82 2 1;
83  
84 __END__
« blib/lib/Astro/App/Satpass2/Format/Template.pm ↑ Summary blib/lib/Astro/App/Satpass2/Copier.pm »