« CPAN/Maker/Bootstrapper/Role/LLM/Annotator.pm
↑ Summary
CPAN/Maker/Bootstrapper/Role/LLM/Utils.pm »
| 1 | package CPAN::Maker::Bootstrapper::Role::ResolveVars; | ||||||||||||||||||||||||||||||||||||||||||
| 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 CLI::Simple::Constants qw(:booleans); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use CLI::Simple::Utils qw(choose slurp); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | Readonly::Scalar our $PLACEHOLDER => qr/[@]([A-Z0-9_]+)[@]/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub cmd_resolve_vars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_resolve_vars: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ($source) = $self->get_args; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | die "ERROR: usage: cmb resolve-var [--vars-file var-file] source-file\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | if !$source; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | die "ERROR: $source not found or not readable\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $source and -r $source
MC/DC0%0/2
-f $source and -r $source
-f $source
-r $source
Truth table0%0/3
A and B
A= -f $sourceB= -r $source
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | if !-f $source || !-r $source; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $vars_file = $self->get_vars_file; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "ERROR: %s is not found or unreadable!\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$vars_file and not -f $vars_file && -r $vars_file
-f $vars_file && -r $vars_file
MC/DC0%0/3
$vars_file and not -f $vars_file && -r $vars_file
$vars_file
-f $vars_file
-r $vars_file
Truth table0%0/4
A and not(B && C)
A= $vars_fileB= -f $vars_fileC= -r $vars_file
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | if $vars_file && ( !-f $vars_file || !-r $vars_file ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $vars_file //= "$source.vars"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$vars_file //= "$source.vars"
MC/DC0%0/1
$vars_file //= "$source.vars"
$vars_file
Truth table0%0/2
A
A= $vars_file
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( -f $vars_file && -r $vars_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $vars_file and -r $vars_file
MC/DC0%0/2
-f $vars_file and -r $vars_file
-f $vars_file
-r $vars_file
Truth table0%0/3
A and B
A= -f $vars_fileB= -r $vars_file
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | foreach my $kv ( split /\n/xsm, slurp($vars_file) ) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | next if !$kv || $kv =~ /^[#]/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $kv or $kv =~ /^[#]/msx
MC/DC0%0/2
not $kv or $kv =~ /^[#]/msx
not $kv
$kv =~ /^[#]/msx
Truth table0%0/3
not(A) or B
A= not $kvB= $kv =~ /^[#]/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ( $k, $v ) = split /[=]/xsm, $kv, 2; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $ENV{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $resolved_text = $self->_resolve_vars( slurp($source) ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | print {*STDOUT} $resolved_text; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _resolve_vars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_vars: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ( $self, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # default strict unless explicitly disabled with --no-strict | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $strict = $self->get_strict; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $strict //= $TRUE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$strict //= $CPAN::Maker::Bootstrapper::Role::ResolveVars::TRUE
MC/DC0%0/2
$strict //= $CPAN::Maker::Bootstrapper::Role::ResolveVars::TRUE
$strict
$CPAN::Maker::Bootstrapper::Role::ResolveVars::TRUE
Truth table0%0/3
A //= B
A= $strictB= $CPAN::Maker::Bootstrapper::Role::ResolveVars::TRUE
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Scrub a COPY for the missing-value check only. Placeholders that | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # appear solely in POD or comments are references, not substitutions, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # so they must not count toward "no value present". Substitution | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # below still runs against the original, untouched $text. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ( my $code = $text ) =~ s/^=\w+.*?^=cut[^\n]*$//gxsm; # strip POD blocks | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $code =~ s/[#][^\n]*//gxsm; # strip comments | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my %in_code = map { $_ => 1 } $code =~ /$PLACEHOLDER/gxsm; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my @missing = sort grep { !( defined $ENV{$_} && length $ENV{$_} ) } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $ENV{$_} && length $ENV{$_}
MC/DC0%0/2
defined $ENV{$_} && length $ENV{$_}
defined $ENV{$_}
length $ENV{$_}
Truth table0%0/3
A && B
A= defined $ENV{$_}B= length $ENV{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | keys %in_code; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (@missing) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $msg = sprintf "no value present for:\n\t%s\n", join "\n\t", @missing; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | die "ERROR: $msg" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | if $strict; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | warn "WARNING: $msg"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Substitute wherever a value exists; anything without a value -- | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # including POD/comment references and (in --no-strict) missing code | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # vars -- is left literal rather than blanked out. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $text =~ s/$PLACEHOLDER/ ( defined $ENV{$1} && length $ENV{$1} ) ? $ENV{$1} : "\@$1\@" /gxsme; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ENV{$1} and length $ENV{$1}
MC/DC0%0/2
defined $ENV{$1} and length $ENV{$1}
defined $ENV{$1}
length $ENV{$1}
Truth table0%0/3
A and B
A= defined $ENV{$1}B= length $ENV{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||