| 1 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||
| 2 | package Text::Template::Simple::Base::Examine; | ||||||||||||||||||||
| 3 | 32 | $Text::Template::Simple::Base::Examine::VERSION = '0.91'; | |||||||||||||||||||
| 4 | 32 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 32 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 32 | ▶ | use Text::Template::Simple::Util qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 32 | ▶ | use Text::Template::Simple::Constants qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 386 | ▶ | sub _examine { | ||||||||||||||||||
|
Subroutine
_examine: called CC=6 SCAR=18.8
| |||||||||||||||||||||
| 11 | 386 | my $self = shift; | |||||||||||||||||||
| 12 | 386 | my $TMP = shift; | |||||||||||||||||||
| 13 | 386 | my($type, $thing) = $self->_examine_type( $TMP ); | |||||||||||||||||||
| 14 | 386 | my $rv; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 386 | ▶ | if ( $type eq 'ERROR' ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 17 | 0 | $rv = $thing; | |||||||||||||||||||
| 18 | 0 | $self->[TYPE] = $type; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | elsif ( $type eq 'GLOB' ) { | ||||||||||||||||||||
| 21 | 0 | $rv = $self->_examine_glob( $thing ); | |||||||||||||||||||
| 22 | 0 | $self->[TYPE] = $type; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | else { | ||||||||||||||||||||
| 25 | 386 | ▶ | if ( my $path = $self->io->file_exists( $thing ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 283 | $rv = $self->io->slurp( $path ); | |||||||||||||||||||
| 27 | 283 | $self->[TYPE] = 'FILE'; | |||||||||||||||||||
| 28 | 283 | $self->[TYPE_FILE] = $path; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||
| 31 | # just die if file is absent, but user forced the type as FILE | ||||||||||||||||||||
| 32 | 103 | ▶ | $self->io->slurp( $thing ) if $type eq 'FILE'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 101 | $rv = $thing; | |||||||||||||||||||
| 34 | 101 | $self->[TYPE] = 'STRING'; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 384 | ▶ | LOG( EXAMINE => sprintf q{%s; LENGTH: %s}, $self->[TYPE], length $rv ) if DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 384 | return $rv; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub _examine_glob { | ||||||||||||||||||
|
Subroutine
_examine_glob: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 43 | 0 | my($self, $thing) = @_; | |||||||||||||||||||
| 44 | 0 | my $type = ref $thing; | |||||||||||||||||||
| 45 | 0 | ▶ | fatal( 'tts.base.examine.notglob' => $type ) if $type ne 'GLOB'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | ▶ | fatal( 'tts.base.examine.notfh' ) if ! fileno $thing; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | return $self->io->slurp( $thing ); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 386 | ▶ | sub _examine_type { | ||||||||||||||||||
|
Subroutine
_examine_type: called CC=7 SCAR=21.0
| |||||||||||||||||||||
| 51 | 386 | my $self = shift; | |||||||||||||||||||
| 52 | 386 | my $TMP = shift; | |||||||||||||||||||
| 53 | 386 | my $ref = ref $TMP; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 386 | ▶ | return EMPTY_STRING , $TMP if ! $ref; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 2 | ▶ | return GLOB => $TMP if $ref eq 'GLOB'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | ▶ | if ( ref $TMP eq 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 2 | ▶ | my $ftype = shift @{ $TMP } || fatal('tts.base.examine._examine_type.ftype'); | ||||||||||||||||||
|
Condition33%1/3
shift @{$TMP;} || fatal('tts.base.examine._examine_type.ftype')
MC/DC0%0/2
shift @{$TMP;} || fatal('tts.base.examine._examine_type.ftype')
shift @{$TMP;}
fatal('tts.base.examine._examine_type.ftype')
Truth table33%1/3
A || B
A= shift @{$TMP;}B= fatal('tts.base.examine._examine_type.ftype')
| |||||||||||||||||||||
| 60 | 2 | ▶ | my $fthing = shift @{ $TMP } || fatal('tts.base.examine._examine_type.fthing'); | ||||||||||||||||||
|
Condition33%1/3
shift @{$TMP;} || fatal('tts.base.examine._examine_type.fthing')
MC/DC0%0/2
shift @{$TMP;} || fatal('tts.base.examine._examine_type.fthing')
shift @{$TMP;}
fatal('tts.base.examine._examine_type.fthing')
Truth table33%1/3
A || B
A= shift @{$TMP;}B= fatal('tts.base.examine._examine_type.fthing')
| |||||||||||||||||||||
| 61 | 2 | ▶ | fatal('tts.base.examine._examine_type.extra') if @{ $TMP }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 2 | return uc $ftype, $fthing; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | return fatal('tts.base.examine._examine_type.unknown', $ref); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 32 | 1; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||