File Coverage

blib/lib/Complete/Program.pm
Criterion Covered Total %
statement 21 21 100.0
branch 5 6 83.3
condition 3 5 60.0
subroutine 5 5 100.0
pod 1 1 100.0
total 35 38 92.1


line stmt bran cond sub pod time code
1             package Complete::Program;
2              
3             our $DATE = '2016-02-06'; # DATE
4             our $VERSION = '0.39'; # VERSION
5              
6 1     1   33649 use 5.010001;
  1         2  
7 1     1   3 use strict;
  1         1  
  1         14  
8 1     1   3 use warnings;
  1         1  
  1         20  
9              
10 1     1   378 use Complete::Common qw(:all);
  1         264  
  1         308  
11              
12             require Exporter;
13             our @ISA = qw(Exporter);
14             our @EXPORT_OK = qw(
15             complete_program
16             );
17              
18             our %SPEC;
19              
20             $SPEC{':package'} = {
21             v => 1.1,
22             summary => 'Completion routines related to program names',
23             };
24              
25             $SPEC{complete_program} = {
26             v => 1.1,
27             summary => 'Complete program name found in PATH',
28             description => <<'_',
29              
30             Windows is supported, on Windows PATH will be split using /;/ instead of /:/.
31              
32             _
33             args => {
34             word => { schema=>[str=>{default=>''}], pos=>0, req=>1 },
35             },
36             result_naked => 1,
37             result => {
38             schema => 'array',
39             },
40             };
41             sub complete_program {
42 6     6 1 4192 require Complete::Util;
43              
44 6         2786 my %args = @_;
45 6   50     14 my $word = $args{word} // "";
46              
47 6 100       47 my @dirs = split(($^O =~ /Win32/ ? qr/;/ : qr/:/), $ENV{PATH});
48 6         10 my @all_progs;
49 6         9 for my $dir (@dirs) {
50 12 50       193 opendir my($dh), $dir or next;
51 12         73 for (readdir($dh)) {
52 42 100 66     403 push @all_progs, $_ if !(-d "$dir/$_") && (-x _);
53             }
54             }
55              
56             Complete::Util::complete_array_elem(
57 6         16 word => $word, array => \@all_progs,
58             );
59             }
60              
61             1;
62             # ABSTRACT: Completion routines related to program names
63              
64             __END__
65              
66             =pod
67              
68             =encoding UTF-8
69              
70             =head1 NAME
71              
72             Complete::Program - Completion routines related to program names
73              
74             =head1 VERSION
75              
76             This document describes version 0.39 of Complete::Program (from Perl distribution Complete-Program), released on 2016-02-06.
77              
78             =head1 DESCRIPTION
79              
80             =head1 FUNCTIONS
81              
82              
83             =head2 complete_program(%args) -> array
84              
85             Complete program name found in PATH.
86              
87             Windows is supported, on Windows PATH will be split using /;/ instead of /:/.
88              
89             This function is not exported by default, but exportable.
90              
91             Arguments ('*' denotes required arguments):
92              
93             =over 4
94              
95             =item * B<word>* => I<str> (default: "")
96              
97             =back
98              
99             Return value: (array)
100              
101             =head1 HOMEPAGE
102              
103             Please visit the project's homepage at L<https://metacpan.org/release/Complete-Program>.
104              
105             =head1 SOURCE
106              
107             Source repository is at L<https://github.com/perlancar/perl-Complete-Program>.
108              
109             =head1 BUGS
110              
111             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Complete-Program>
112              
113             When submitting a bug or request, please include a test-file or a
114             patch to an existing test-file that illustrates the bug or desired
115             feature.
116              
117             =head1 SEE ALSO
118              
119             L<Complete>
120              
121             Other C<Complete::*> modules.
122              
123             =head1 AUTHOR
124              
125             perlancar <perlancar@cpan.org>
126              
127             =head1 COPYRIGHT AND LICENSE
128              
129             This software is copyright (c) 2016 by perlancar@cpan.org.
130              
131             This is free software; you can redistribute it and/or modify it under
132             the same terms as the Perl 5 programming language system itself.
133              
134             =cut