Completion/Path.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 53 CC 3 SCAR 12.8
CC
3
Cov
0%
Complete
6.0
get_choices
6.0
_get_defaults
2.0
CRAP 3.6
1 package Term::Completion::Path;
2
3 use strict;
4 use warnings;
5 use File::Spec;
6
7 our $VERSION = '0.90';
8
9 our @EXPORT_OK = qw(Complete);
10 use base qw(Term::Completion);
11
12 # ugly way to get the separator - an API for that would be nice
13 my $sep = File::Spec->catfile(qw(A B));
14 if($sep) {
15 $sep =~ s/^A|B$//g;
16 } else {
17 $sep = ($^O =~ /win/i ? "\\" : "/");
18 }
19
20 our %DEFAULTS = (
21 sep => $sep
22 );
23
24 sub _get_defaults
25 {
26 return(__PACKAGE__->SUPER::_get_defaults(), %DEFAULTS);
27 }
28
29 sub Complete
30 {
31 my $prompt = shift;
32 $prompt = '' unless defined $prompt;
33 __PACKAGE__->new(prompt => $prompt)->complete;
34 }
35
36 sub get_choices
37 {
38 my __PACKAGE__ $this = shift;
39 my $sep = $this->{sep};
40 map { (-d) ? "$_$sep" : $_ } glob("$_[0]*");
41 }
42
43 sub post_process
44 {
45 my __PACKAGE__ $this = shift;
46 my $return = $this->SUPER::post_process(shift);
47 my $sep = $this->{sep};
48 $return =~ s/\Q$sep\E$//;
49 $return;
50 }
51
52 # TODO validate should have methods to check for file/dir/link
53
54 1;
55
56 __END__