Spec/Plugin/Meta.pm

filter: Statementstmt 53.6% 22 / 41 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 48.3% 30 / 62 CC 6 SCAR 30.0
CC
6
Cov
43%
cmd_self_completion
42.0
__ANON__
2.0
cmd_self_pod
2.0
CRAP 20.1
« Spec/Plugin/Format.pm ↑ Summary Spec.pm »
1 # ABSTRACT: App::Spec Plugin for meta functions
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package App::Spec::Plugin::Meta;
5 6 our $VERSION = 'v0.15.1'; # TRIAL VERSION
6  
7 6 ▶use List::Util qw/ any /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 with 'App::Spec::Role::Plugin::Subcommand';
11  
12 6 my $yaml = do { local $/; <DATA> };
13  
14 37 ▶sub install_subcommands {
Subroutine install_subcommands: called CC=1 SCAR=0.0
Pod documented
15 37 my ($class, %args) = @_;
16 37 my $parent = $args{spec};
17 37 my $appspec = App::Spec::Subcommand->read(\$yaml);
18 37 return $appspec;
19 }
20  
21 0 ▶sub cmd_self_completion {
Subroutine cmd_self_completion: not called CC=6 SCAR=37.4
Pod documented
22 0 my ($self, $run) = @_;
23 0 my $options = $run->options;
24 0 ▶ my $shell = $options->{zsh} ? "zsh" : $options->{bash} ? "bash" : $options->{fish} ? "fish" : '';
Branch: 3 branches
BranchTrueFalseTotal
$options->{'zsh'} ? : 0 0 0
$options->{'bash'} ? : 0 0 0
$options->{'fish'} ? : 0 0 0
25 0 ▶ unless ($shell) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shell) 0 0 0
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 ▶ unless (any { $_ eq $shell } qw/ bash zsh fish / ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless (&any(sub { $_ eq $shell; } , "bash", "zsh", "fish")) 0 0 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 0 ▶sub cmd_self_pod {
Subroutine cmd_self_pod: not called CC=1 SCAR=6.9
Pod documented
42 0 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 6 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<App::Spec> 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<app meta completion generate>
78  
79 =item cmd_self_pod
80  
81 This is called by C<app meta pod generate>
82  
83 =item install_subcommands
84  
85 See L<App::Spec::Role::Plugin::Subcommand#install_subcommands>
86  
87 =back
88  
89 =cut
90  
91 __DATA__
« Spec/Plugin/Format.pm ↑ Summary Spec.pm »