File Coverage

blib/lib/MooseX/App/Plugin/ZshCompletion.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 23 23 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: zsh completion for your MooseX::App applications
2 2     2   17548 use strict;
  2         4  
  2         56  
3 2     2   10 use warnings;
  2         4  
  2         79  
4             package MooseX::App::Plugin::ZshCompletion;
5              
6 2     2   59 use 5.010;
  2         6  
7              
8             our $VERSION = '0.002'; # VERSION
9              
10 2     2   751 use namespace::autoclean;
  2         20144  
  2         11  
11 2     2   867 use Moose::Role;
  2         483557  
  2         12  
12              
13             sub plugin_metaroles {
14 1     1 1 4672 my ($self,$class) = @_;
15              
16             return {
17 1         7 class => ['MooseX::App::Plugin::ZshCompletion::Meta::Class'],
18             }
19             }
20              
21             around 'initialize_command_class' => sub {
22             my $orig = shift;
23             my $self = shift;
24              
25             my $return = $self->$orig(@_);
26             if (blessed $return
27             && $return->isa('MooseX::App::Plugin::ZshCompletion::Command')) {
28             return $return->zsh_completion($self);
29             }
30              
31             return $return;
32             };
33              
34             1;
35              
36             __END__
37              
38             =encoding utf8
39              
40             =head1 NAME
41              
42             MooseX::App::Plugin::ZshCompletion - zsh completion for your MooseX::App applications
43              
44             =head1 SYNOPSIS
45              
46             In your base class:
47              
48             package MyApp;
49             use MooseX::App qw/ ZshCompletion /;
50              
51             In your .zshrc:
52              
53             fpath=('completion-dir/zsh' $fpath)
54              
55             In your shell
56              
57             zsh% myapp zsh_completion > completion-dir/_myapp
58             zsh% chmod u+x completion-dir/_myapp
59             zsh% exec zsh
60              
61             =head1 DESCRIPTION
62              
63             This plugin generates a zsh completion definition for your application.
64              
65             Completion works for subcommands, parameters and options. If an option or
66             parameter is declared as an C<enum> with L<Moose::Meta::TypeConstraint> you
67             will get a completion for the enum values.
68              
69             Option completions will show its descriptions also.
70              
71             The default completion type for parameters is C<_files>
72              
73             In the examples directory you find C<myapp>.
74              
75             % myapp <TAB>
76             bash_completion fetch_mail help lala zsh_completion
77              
78             % myapp fetch_mail server.example -<TAB>
79             --dir -- Output 'dir'
80             --max -- Maximum number of emails to fetch
81             --servertype -- Mailserver type: IMAP or POP3
82             --usage --help -h -- Prints this usage information.
83             --user -- User
84             --verbose -- be verbose
85              
86             % myapp fetch_mail server.example --servertype <TAB>
87             IMAP POP3
88              
89             =head1 METHODS
90              
91             =over 4
92              
93             =item plugin_metaroles
94              
95             =back
96              
97             =head1 SEE ALSO
98              
99             L<MooseX::App::Plugin::BashCompletion>
100              
101             =head1 LICENSE
102              
103             COPYRIGHT AND LICENSE
104              
105             Copyright (C) 2015 by Tina Mueller
106              
107             This library is free software; you can redistribute it and/or modify it under
108             the same terms as Perl itself. The full text of the license can be found
109             in the LICENSE file.
110              
111             =cut
112