| 1 | package Complete::Env; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | our $DATE = '2017-12-31'; # DATE | |||||||||||
| 4 | 4 | our $VERSION = '0.400'; # VERSION | |||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 4 | ▶ | use Complete::Common qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 4 | require Exporter; | |||||||||||
| 13 | 4 | our @ISA = qw(Exporter); | |||||||||||
| 14 | 4 | our @EXPORT_OK = qw( | |||||||||||
| 15 | complete_env | ||||||||||||
| 16 | complete_env_elem | ||||||||||||
| 17 | complete_path_env_elem | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | 4 | our %SPEC; | |||||||||||
| 21 | |||||||||||||
| 22 | 4 | $SPEC{':package'} = { | |||||||||||
| 23 | v => 1.1, | ||||||||||||
| 24 | summary => 'Completion routines related to environment variables', | ||||||||||||
| 25 | }; | ||||||||||||
| 26 | |||||||||||||
| 27 | $SPEC{complete_env} = { | ||||||||||||
| 28 | 4 | v => 1.1, | |||||||||||
| 29 | summary => 'Complete from environment variables', | ||||||||||||
| 30 | description => <<'_', | ||||||||||||
| 31 | |||||||||||||
| 32 | On Windows, environment variable names are all converted to uppercase. You can | ||||||||||||
| 33 | use case-insensitive option (`ci`) to match against original casing. | ||||||||||||
| 34 | |||||||||||||
| 35 | _ | ||||||||||||
| 36 | args => { | ||||||||||||
| 37 | %arg_word, | ||||||||||||
| 38 | }, | ||||||||||||
| 39 | result_naked => 1, | ||||||||||||
| 40 | result => { | ||||||||||||
| 41 | schema => 'array', | ||||||||||||
| 42 | }, | ||||||||||||
| 43 | }; | ||||||||||||
| 44 | 1 | ▶ | sub complete_env { | ||||||||||
|
Subroutine
complete_env: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||
| 45 | 1 | require Complete::Util; | |||||||||||
| 46 | |||||||||||||
| 47 | 1 | my %args = @_; | |||||||||||
| 48 | 1 | ▶ | my $word = $args{word} // ""; | ||||||||||
|
Condition50%1/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table50%1/2
A
A= $args{"word"}
| |||||||||||||
| 49 | 1 | ▶ | if ($word =~ /^\$/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | Complete::Util::complete_array_elem( | ||||||||||||
| 51 | 0 | word=>$word, array=>[map {"\$$_"} keys %ENV], | |||||||||||
| 52 | ); | ||||||||||||
| 53 | } else { | ||||||||||||
| 54 | 1 | Complete::Util::complete_array_elem( | |||||||||||
| 55 | word=>$word, array=>[keys %ENV], | ||||||||||||
| 56 | ); | ||||||||||||
| 57 | } | ||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | $SPEC{complete_env_elem} = { | ||||||||||||
| 61 | 4 | v => 1.1, | |||||||||||
| 62 | summary => 'Complete from elements of an environment variable', | ||||||||||||
| 63 | description => <<'_', | ||||||||||||
| 64 | |||||||||||||
| 65 | An environment variable like PATH contains colon- (or, on Windows, semicolon-) | ||||||||||||
| 66 | separated elements. This routine complete from the elements of such variable. | ||||||||||||
| 67 | |||||||||||||
| 68 | _ | ||||||||||||
| 69 | args => { | ||||||||||||
| 70 | %arg_word, | ||||||||||||
| 71 | env => { | ||||||||||||
| 72 | summary => 'Name of environment variable to use', | ||||||||||||
| 73 | schema => 'str*', | ||||||||||||
| 74 | req => 1, | ||||||||||||
| 75 | pos => 1, | ||||||||||||
| 76 | }, | ||||||||||||
| 77 | }, | ||||||||||||
| 78 | result_naked => 1, | ||||||||||||
| 79 | result => { | ||||||||||||
| 80 | schema => 'array', | ||||||||||||
| 81 | }, | ||||||||||||
| 82 | }; | ||||||||||||
| 83 | 2 | ▶ | sub complete_env_elem { | ||||||||||
|
Subroutine
complete_env_elem: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||
| 84 | 2 | require Complete::Util; | |||||||||||
| 85 | |||||||||||||
| 86 | 2 | my %args = @_; | |||||||||||
| 87 | 2 | ▶ | my $word = $args{word} // ""; | ||||||||||
|
Condition50%1/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table50%1/2
A
A= $args{"word"}
| |||||||||||||
| 88 | 2 | my $env = $args{env}; | |||||||||||
| 89 | 2 | my @elems; | |||||||||||
| 90 | 2 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | 0 | ▶ | @elems = split /;/, ($ENV{$env} // ''); | ||||||||||
|
Condition0%0/2
$ENV{$env} // ""
MC/DC0%0/1
$ENV{$env} // ""
$ENV{$env}
Truth table0%0/2
A
A= $ENV{$env}
| |||||||||||||
| 92 | } else { | ||||||||||||
| 93 | 2 | ▶ | @elems = split /:/, ($ENV{$env} // ''); | ||||||||||
|
Condition50%1/2
$ENV{$env} // ""
MC/DC0%0/1
$ENV{$env} // ""
$ENV{$env}
Truth table50%1/2
A
A= $ENV{$env}
| |||||||||||||
| 94 | } | ||||||||||||
| 95 | 2 | Complete::Util::complete_array_elem( | |||||||||||
| 96 | word=>$word, array=>\@elems, | ||||||||||||
| 97 | ); | ||||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | $SPEC{complete_path_env_elem} = { | ||||||||||||
| 101 | 4 | v => 1.1, | |||||||||||
| 102 | summary => 'Complete from elements of PATH environment variable', | ||||||||||||
| 103 | description => <<'_', | ||||||||||||
| 104 | |||||||||||||
| 105 | PATH environment variable contains colon- (or, on Windows, semicolon-) separated | ||||||||||||
| 106 | elements. This routine complete from those elements. | ||||||||||||
| 107 | |||||||||||||
| 108 | _ | ||||||||||||
| 109 | args => { | ||||||||||||
| 110 | %arg_word, | ||||||||||||
| 111 | }, | ||||||||||||
| 112 | result_naked => 1, | ||||||||||||
| 113 | result => { | ||||||||||||
| 114 | schema => 'array', | ||||||||||||
| 115 | }, | ||||||||||||
| 116 | }; | ||||||||||||
| 117 | 1 | ▶ | sub complete_path_env_elem { | ||||||||||
|
Subroutine
complete_path_env_elem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 118 | 1 | my %args = @_; | |||||||||||
| 119 | 1 | complete_env_elem(word => $args{word}, env => 'PATH'); | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 4 | 1; | |||||||||||
| 123 | # ABSTRACT: Completion routines related to environment variables | ||||||||||||
| 124 | |||||||||||||
| 125 | __END__ | ||||||||||||