| 1 | ## no critic (RequireUseStrict) | ||
| 2 | package Bash::Completion::Plugins::App::Cmd; | ||
| 3 | { | ||
| 4 | 2 | $Bash::Completion::Plugins::App::Cmd::VERSION = '0.01'; | |
| 5 | } | ||
| 6 | |||
| 7 | ## use critic (RequireUseStrict) | ||
| 8 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use parent 'Bash::Completion::Plugin'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 2 | ▶ | use Bash::Completion::Utils qw(prefix_match); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 2 | ▶ | use Class::Load qw(load_class); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | sub complete { | ||
| 16 | 4 | ▶ | my ( $self, $r ) = @_; |
|
Subroutine
complete: called CC=1 SCAR=0.0
Pod
documented
| |||
| 17 | |||
| 18 | 4 | my $class = $self->command_class; | |
| 19 | 4 | load_class($class); | |
| 20 | |||
| 21 | 4 | my @names = $class->command_names; | |
| 22 | |||
| 23 | 4 | $r->candidates(prefix_match($r->word, @names)); | |
| 24 | } | ||
| 25 | |||
| 26 | 2 | 1; | |
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | =pod | ||
| 31 | |||
| 32 | =head1 NAME | ||
| 33 | |||
| 34 | Bash::Completion::Plugins::App::Cmd - A Bash::Completion plugin for writing App::Cmd plugins | ||
| 35 | |||
| 36 | =head1 VERSION | ||
| 37 | |||
| 38 | version 0.01 | ||
| 39 | |||
| 40 | =head1 SYNOPSIS | ||
| 41 | |||
| 42 | use parent 'Bash::Completion::Plugins::App::Cmd'; | ||
| 43 | |||
| 44 | # fill in everything you normally would for Bash::Completion, | ||
| 45 | # except for complete | ||
| 46 | |||
| 47 | sub command_class { 'My::Cmd' } # mandatory | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | This is a L<Bash::Completion> plugin that assists in writing other | ||
| 52 | L<Bash::Completion> plugins for programs that use L<App::Cmd>. Everything | ||
| 53 | is done similar to writing a normal L<Bash::Completion> plugin, except you | ||
| 54 | need to define the L</command_class> method rather than the | ||
| 55 | L<'Bash::Completion::Plugin'/complete> method. L</command_class> is | ||
| 56 | the name of the class that you use C<use App::Cmd::Setup -app> from. | ||
| 57 | |||
| 58 | =head1 METHODS | ||
| 59 | |||
| 60 | =head2 complete | ||
| 61 | |||
| 62 | Populates the L<Bash::Completion> request with commands from the | ||
| 63 | given L<App::Cmd> class. | ||
| 64 | |||
| 65 | =head2 command_class | ||
| 66 | |||
| 67 | Returns the name of the class that this plugin will extract command | ||
| 68 | names from. This method must be implemented by subclasses. | ||
| 69 | |||
| 70 | =head1 SEE ALSO | ||
| 71 | |||
| 72 | L<App::Cmd>, L<Bash::Completion> | ||
| 73 | |||
| 74 | =head1 AUTHOR | ||
| 75 | |||
| 76 | Rob Hoelz <rob@hoelz.ro> | ||
| 77 | |||
| 78 | =head1 COPYRIGHT AND LICENSE | ||
| 79 | |||
| 80 | This software is copyright (c) 2012 by Rob Hoelz. | ||
| 81 | |||
| 82 | This is free software; you can redistribute it and/or modify it under | ||
| 83 | the same terms as the Perl 5 programming language system itself. | ||
| 84 | |||
| 85 | =head1 BUGS | ||
| 86 | |||
| 87 | Please report any bugs or feature requests on the bugtracker website | ||
| 88 | https://github.com/hoelzro/bash-completion-plugins-app-cmd/issues | ||
| 89 | |||
| 90 | When submitting a bug or request, please include a test-file or a | ||
| 91 | patch to an existing test-file that illustrates the bug or desired | ||
| 92 | feature. | ||
| 93 | |||
| 94 | =cut | ||
| 95 | |||
| 96 | |||
| 97 | __END__ | ||