| 1 | package Reply::Plugin::Autocomplete::Globals; | ||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:DOY'; | |||||||||||||||||||||||||||
| 3 | 1 | $Reply::Plugin::Autocomplete::Globals::VERSION = '0.42'; | |||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: tab completion for global variables | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'Reply::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Reply::Util qw($fq_ident_rx $fq_varname_rx); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | return $self; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub tab_handler { | ||||||||||||||||||||||||||
|
Subroutine
tab_handler: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 0 | my ($line) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my ($maybe_var) = $line =~ /($fq_varname_rx)$/; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | return unless $maybe_var; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | $maybe_var =~ s/\s+//g; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my ($sigil, $rest) = $maybe_var =~ /(.)(.*)/; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | my @parts = split '::', $rest, -1; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if grep { /:/ } @parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return if @parts && $parts[0] =~ /^[0-9]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@parts and $parts[0] =~ /^[0-9]/
MC/DC0%0/2
@parts and $parts[0] =~ /^[0-9]/
@parts
$parts[0] =~ /^[0-9]/
Truth table0%0/3
A and B
A= @partsB= $parts[0] =~ /^[0-9]/
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $var_prefix = pop @parts; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | $var_prefix = '' unless defined $var_prefix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $stash_name = join('::', @parts); | |||||||||||||||||||||||||||
| 41 | 0 | my $stash = eval { | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | Package::Stash->new(@parts ? $stash_name : 'main') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return unless $stash; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my @symbols = map { s/^(.)main::/$1/; $_ } _recursive_symbols($stash); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $prefix = $stash_name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | ? $stash_name . '::' . $var_prefix | ||||||||||||||||||||||||||||
| 50 | : $var_prefix; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my @results; | |||||||||||||||||||||||||||
| 53 | 0 | for my $global (@symbols) { | |||||||||||||||||||||||||||
| 54 | 0 | my ($global_sigil, $global_name) = $global =~ /(.)(.*)/; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | next unless index($global_name, $prefix) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # this is weird, not sure why % gets stripped but not $ or @ | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($sigil eq $global_sigil) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | push @results, $sigil eq '%' ? $global : $global_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | ▶ | elsif ($global_sigil eq '@' && $sigil eq '$') { | |||||||||||||||||||||||||||
|
Condition0%0/3
$global_sigil eq "\@" and $sigil eq "\$"
MC/DC0%0/2
$global_sigil eq "\@" and $sigil eq "\$"
$global_sigil eq "\@"
$sigil eq "\$"
Truth table0%0/3
A and B
A= $global_sigil eq "\@"B= $sigil eq "\$"
| |||||||||||||||||||||||||||||
| 62 | 0 | push @results, "$global_name\["; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | elsif ($global_sigil eq '%') { | ||||||||||||||||||||||||||||
| 65 | 0 | push @results, "$global_name\{"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return @results; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _recursive_symbols { | ||||||||||||||||||||||||||
|
Subroutine
_recursive_symbols: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 73 | 0 | my ($stash) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $stash_name = $stash->name; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @symbols; | |||||||||||||||||||||||||||
| 78 | 0 | for my $name ($stash->list_all_symbols) { | |||||||||||||||||||||||||||
| 79 | # main can have things in it like "_<reader Foo::bar (defined at ...)" | ||||||||||||||||||||||||||||
| 80 | # which aren't real variables - don't complete them, because we only | ||||||||||||||||||||||||||||
| 81 | # care about things that can be used as literal variable names. be sure | ||||||||||||||||||||||||||||
| 82 | # to not also block out punctuation variables. | ||||||||||||||||||||||||||||
| 83 | # XXX fix for unicode | ||||||||||||||||||||||||||||
| 84 | # XXX fix for variables like ${^GLOBAL_PHASE} | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | next unless $name =~ /^$fq_ident_rx(?:::)?$/ || length($name) == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name =~ /^$Reply::Plugin::Autocomplete::Globals::fq_ident_rx(?:::)?$/ or length $name == 1
MC/DC0%0/2
$name =~ /^$Reply::Plugin::Autocomplete::Globals::fq_ident_rx(?:::)?$/ or length $name == 1
$name =~ /^$Reply::Plugin::Autocomplete::Globals::fq_ident_rx(?:::)?$/
length $name == 1
Truth table0%0/3
A or B
A= $name =~ /^$Reply::Plugin::Autocomplete::Globals::fq_ident_rx(?:::)?$/B= length $name == 1
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($name =~ s/::$//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | my $next = Package::Stash->new(join('::', $stash_name, $name)); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | next if $next->namespace == $stash->namespace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | push @symbols, _recursive_symbols($next); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | push @symbols, "\$${stash_name}::$name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | if $stash->has_symbol("\$$name"); | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | push @symbols, "\@${stash_name}::$name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | if $stash->has_symbol("\@$name"); | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | push @symbols, "\%${stash_name}::$name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | if $stash->has_symbol("\%$name"); | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | push @symbols, "\&${stash_name}::$name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | if $stash->has_symbol("\&$name"); | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | push @symbols, "\*${stash_name}::$name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | if $stash->has_symbol($name); | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return @symbols; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||