| 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
| |||||||||||||||
| 30 | 2 | ▶ | if ( $dumper_default ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 47 | 2 | my $val = shift @args; | |||||||||||||
| 48 | 2 | my $ref = ref $val; | |||||||||||||
| 49 | 2 | ▶ | if ( ! $ref ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 50 | 2 | foreach my $possible ( split qr{ , }smx, $val ) { | |||||||||||||
| 51 | 2 | ▶ | my $code = $dumper_hash{$possible} or next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 2 | ▶ | load_package( $possible ) or next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 2 | ▶ | $code = $possible->can( $code ) or next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 2 | $val = $code; | |||||||||||||
| 55 | 2 | last; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 2 | ▶ | ref $val | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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__ | ||||||||||||||