| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ABSTRACT: App::Spec Plugin for meta functions | 
| 2 | 3 |  |  | 3 |  | 1878 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 107 |  | 
| 3 | 3 |  |  | 3 |  | 16 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 185 |  | 
| 4 |  |  |  |  |  |  | package App::Spec::Plugin::Meta; | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.011'; # VERSION | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 18 | use List::Util qw/ any /; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 240 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 3 |  |  | 3 |  | 20 | use Moo; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 21 |  | 
| 10 |  |  |  |  |  |  | with 'App::Spec::Role::Plugin::Subcommand'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | my $yaml = do { local $/;  }; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub install_subcommands { | 
| 15 | 29 |  |  | 29 | 1 | 129 | my ($class, %args) = @_; | 
| 16 | 29 |  |  |  |  | 86 | my $parent = $args{spec}; | 
| 17 | 29 |  |  |  |  | 159 | my $appspec = App::Spec::Subcommand->read(\$yaml); | 
| 18 | 29 |  |  |  |  | 123 | return $appspec; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub cmd_self_completion { | 
| 22 | 0 |  |  | 0 | 1 |  | my ($self, $run) = @_; | 
| 23 | 0 |  |  |  |  |  | my $options = $run->options; | 
| 24 | 0 | 0 |  |  |  |  | my $shell = $options->{zsh} ? "zsh" : $options->{bash} ? "bash" : ''; | 
|  |  | 0 |  |  |  |  |  | 
| 25 | 0 | 0 |  |  |  |  | unless ($shell) { | 
| 26 | 0 |  |  |  |  |  | my $ppid = getppid(); | 
| 27 | 0 |  |  |  |  |  | chomp($shell = `ps --no-headers -o cmd $ppid`); | 
| 28 | 0 |  |  |  |  |  | $shell =~ s/.*\W(\w*sh).*$/$1/; #handling case of '-zsh' or '/bin/bash' | 
| 29 |  |  |  |  |  |  | #or bash -i -rs | 
| 30 |  |  |  |  |  |  | } | 
| 31 | 0 | 0 |  | 0 |  |  | unless (any { $_ eq $shell } qw/ bash zsh / ) { | 
|  | 0 |  |  |  |  |  |  | 
| 32 | 0 |  |  |  |  |  | die "Specify which shell, '$shell' not supported"; | 
| 33 |  |  |  |  |  |  | } | 
| 34 | 0 |  |  |  |  |  | my $spec = $run->spec; | 
| 35 | 0 |  |  |  |  |  | my $completion = $spec->generate_completion( | 
| 36 |  |  |  |  |  |  | shell => $shell, | 
| 37 |  |  |  |  |  |  | ); | 
| 38 | 0 |  |  |  |  |  | $run->out($completion); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub cmd_self_pod { | 
| 42 | 0 |  |  | 0 | 1 |  | my ($self, $run) = @_; | 
| 43 | 0 |  |  |  |  |  | my $spec = $run->spec; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | require App::Spec::Pod; | 
| 46 | 0 |  |  |  |  |  | my $generator = App::Spec::Pod->new( | 
| 47 |  |  |  |  |  |  | spec => $self, | 
| 48 |  |  |  |  |  |  | ); | 
| 49 | 0 |  |  |  |  |  | my $pod = $generator->generate; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | $run->out($pod); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | 1; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =pod | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head1 NAME | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | App::Spec::Plugin::Meta - App::Spec Plugin for meta functions | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | This plugin is enabled in L by default. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | It adds the following commands to your app: | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | % app meta completion generate | 
| 69 |  |  |  |  |  |  | % app meta pod generate | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 METHODS | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =over 4 | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =item cmd_self_completion | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | This is called by C | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =item cmd_self_pod | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | This is called by C | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =item install_subcommands | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | See L | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =back | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =cut | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | __DATA__ |