CLI/Argument/Filename.pm

filter: Statementstmt 75.8% 47 / 62 Branchbran 65.3% 17 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 75.7% 75 / 99 CC 15 SCAR 22.7
CC
15
Cov
73%
glob_complete
13.9
complete
12.2
BEGIN
1.0
CRAP 9.7
« CLI/Command.pm ↑ Summary CLI.pm »
1 #=============================================================================
2 #
3 # Module: Term::CLI::Argument::Filename
4 #
5 # Description: Class for file name arguments in Term::CLI
6 #
7 # Author: Steven Bakker (SBAKKER), <cpanman@monkey-mind.net>
8 # Created: 23/01/18
9 #
10 # Copyright (c) 2022 Steven Bakker
11 #
12 # This module is free software; you can redistribute it and/or modify
13 # it under the same terms as Perl itself. See "perldoc perlartistic."
14 #
15 # This software is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 #
19 #=============================================================================
20  
21 package Term::CLI::Argument::Filename 0.061001;
22  
23 7 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 7 ▶use Moo 1.000001;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 7 ▶use namespace::clean 0.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 7 extends 'Term::CLI::Argument';
29  
30 7 ▶use File::Glob 'bsd_glob';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 7 ▶use Fcntl ':mode';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 7 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 5 ▶sub complete {
Subroutine complete: called CC=4 SCAR=25.0
Pod documented
36 5 my ( $self, $text ) = @_;
37  
38 my $func_ref = $self->term->Attribs->{filename_completion_function}
39 5 ▶ or return $self->glob_complete($text);
Branch: 1 branch
BranchTrueFalseTotal
my $func_ref = $self->term->Attribs->{"filename_completion_function"} or return $self->glob_complete($text) 0 5 5
40  
41 0 ▶ if ($func_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func_ref) 0 0 0
42 0 my $state = 0;
43 0 my @list;
44 0 ▶ while ( my $f = $func_ref->( $text, $state ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = &$func_ref($text, $state)) 0 0 0
45 0 push @list, $f;
46 0 $state = 1;
47 }
48 0 return @list;
49 }
50 }
51  
52 10 ▶sub glob_complete {
Subroutine glob_complete: called CC=12 SCAR=26.3
Pod documented
53 10 my ( $self, $text ) = @_;
54 10 my @list = bsd_glob("$text*");
55  
56 10 ▶ return if @list == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @list == 0 2 8 10
57  
58 8 ▶ if (@list == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list == 1) 4 4 8
59 4 ▶ if (-d $list[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $list[0]) 2 2 4
60 # Dumb trick to get readline to expand a directory
61 # with a trailing "/", but *not* add a space.
62 # Simulates the way GNU readline does it.
63 2 return ("$list[0]/", "$list[0]//");
64 }
65 2 return @list;
66 }
67  
68 # Add filetype suffixes if there is more than one possible completion.
69 4 foreach (@list) {
70 14 lstat;
71 14 ▶ if ( -l _ ) { $_ .= q{@}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-l _) 2 12 14
72 12 ▶ if ( -d _ ) { $_ .= q{/}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) 2 10 12
73 0 ▶ if ( -c _ ) { $_ .= q{%}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-c _) 0 10 10
74 0 ▶ if ( -b _ ) { $_ .= q{#}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-b _) 0 10 10
75 0 ▶ if ( -S _ ) { $_ .= q{=}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-S _) 0 10 10
76 0 ▶ if ( -p _ ) { $_ .= q{=}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-p _) 0 10 10
77 10 ▶ if ( -x _ ) { $_ .= q{*}; next }
Branch: 1 branch
BranchTrueFalseTotal
if (-x _) 2 8 10
78 }
79 4 return @list;
80 }
81  
82 7 1;
83  
84 __END__
« CLI/Command.pm ↑ Summary CLI.pm »