| 1 | package Bash::Completion; | ||||||||||
| 2 | { | ||||||||||
| 3 | 3 | $Bash::Completion::VERSION = '0.008'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Extensible system to provide bash completion | ||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Bash::Completion::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Module::Load (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | use Module::Pluggable | ||||||||||
| 13 | 3 | ▶ | search_path => ['Bash::Completion::Plugins'], | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | sub_name => 'plugin_names'; | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 4 | ▶ | sub new { return bless {}, $_[0] } | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | sub complete { | ||||||||
|
Subroutine
complete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 22 | 3 | my ($self, $plugin, $cmd_line) = @_; | |||||||||
| 23 | |||||||||||
| 24 | 3 | my $class = "Bash::Completion::Plugins::$plugin"; | |||||||||
| 25 | 3 | ▶ | return unless $self->_load_class($class); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 3 | my $req = Bash::Completion::Request->new; | |||||||||
| 28 | 3 | $class->new(args => $cmd_line)->complete($req); | |||||||||
| 29 | |||||||||||
| 30 | 3 | return $req; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 1 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 36 | 1 | my ($self) = @_; | |||||||||
| 37 | 1 | my $script = ''; | |||||||||
| 38 | |||||||||||
| 39 | 1 | for my $plugin ($self->plugins) { | |||||||||
| 40 | 2 | my $cmds = $plugin->should_activate; | |||||||||
| 41 | 2 | ▶ | next unless @$cmds; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | 2 | my $snippet = $plugin->generate_bash_setup($cmds); | |||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | if (ref $snippet) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | my $options = join(' ', map {"-o $_"} @$snippet); | |||||||||
| 47 | 2 | my $plugin_name = ref($plugin); | |||||||||
| 48 | 2 | $plugin_name =~ s/^Bash::Completion::Plugins:://; | |||||||||
| 49 | |||||||||||
| 50 | $snippet = join( | ||||||||||
| 51 | "\n", | ||||||||||
| 52 | map { | ||||||||||
| 53 | 2 | qq{complete -C 'bash-complete complete $plugin_name -- ' $options $_} | |||||||||
| 54 | } @$cmds | ||||||||||
| 55 | ); | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 2 | ▶ | $script .= "$snippet\n" if $snippet; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | return $script; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | 2 | ▶ | sub plugins { | ||||||||
|
Subroutine
plugins: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 67 | 2 | my ($self) = @_; | |||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | unless ($self->{plugins}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | my @plugins; | |||||||||
| 71 | |||||||||||
| 72 | 1 | for my $plugin_name ($self->plugin_names) { | |||||||||
| 73 | 2 | ▶ | next unless $self->_load_class($plugin_name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 2 | push @plugins, $plugin_name->new; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 1 | $self->{plugins} = \@plugins; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 2 | return @{$self->{plugins}}; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | ####### | ||||||||||
| 86 | # Utils | ||||||||||
| 87 | |||||||||||
| 88 | 5 | ▶ | sub _load_class { | ||||||||
|
Subroutine
_load_class: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 5 | eval { Module::Load::load($_[1]); 1 }; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 3 | 1; | |||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | __END__ | ||||||||||