| 1 | package Complete::Regexp::Pattern; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $DATE = '2016-12-31'; # DATE | |||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Complete::Common qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our %SPEC; | |||||||||||||||||||||||||||
| 14 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 15 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 16 | 1 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 17 | complete_regexp_pattern_pattern | ||||||||||||||||||||||||||||
| 18 | complete_regexp_pattern_module | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | $SPEC{':package'} = { | |||||||||||||||||||||||||||
| 22 | v => 1.1, | ||||||||||||||||||||||||||||
| 23 | summary => 'Completion routines for Regexp::Pattern', | ||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $SPEC{complete_regexp_pattern_module} = { | ||||||||||||||||||||||||||||
| 27 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 28 | summary => 'Complete with Regexp::Pattern::* module, without the Regexp::Pattern:: prefix', | ||||||||||||||||||||||||||||
| 29 | description => <<'_', | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | This is just a thin wrapper for: | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Complete::Module::complete_module(ns_prefix=>'Regexp::Pattern', ...) | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | _ | ||||||||||||||||||||||||||||
| 36 | args => { | ||||||||||||||||||||||||||||
| 37 | %arg_word, | ||||||||||||||||||||||||||||
| 38 | path_sep => { | ||||||||||||||||||||||||||||
| 39 | summary => 'Will be passed to Complete::Module::complete_module', | ||||||||||||||||||||||||||||
| 40 | schema => 'str*', | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | result_naked => 1, | ||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub complete_regexp_pattern_module { | ||||||||||||||||||||||||||
|
Subroutine
complete_regexp_pattern_module: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | require Complete::Module; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Complete::Module::complete_module( | ||||||||||||||||||||||||||||
| 51 | ns_prefix => 'Regexp::Pattern', | ||||||||||||||||||||||||||||
| 52 | word => $args{word}, | ||||||||||||||||||||||||||||
| 53 | 0 | (path_sep => $args{path_sep}) x defined($args{path_sep}), | |||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | $SPEC{complete_regexp_pattern_pattern} = { | ||||||||||||||||||||||||||||
| 58 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 59 | summary => 'Complete Regep::Pattern name, e.g. YouTube::video_id', | ||||||||||||||||||||||||||||
| 60 | description => <<'_', | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | The name is qualified with its module name, without the `Regexp::Pattern::` | ||||||||||||||||||||||||||||
| 63 | prefix. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | _ | ||||||||||||||||||||||||||||
| 66 | args => { | ||||||||||||||||||||||||||||
| 67 | %arg_word, | ||||||||||||||||||||||||||||
| 68 | path_sep => { | ||||||||||||||||||||||||||||
| 69 | schema => 'str*', | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||
| 72 | result_naked => 1, | ||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub complete_regexp_pattern_pattern { | ||||||||||||||||||||||||||
|
Subroutine
complete_regexp_pattern_pattern: not called CC=6 SCAR=36.3
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | require Complete::Path; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $word = $args{word} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
| |||||||||||||||||||||||||||||
| 80 | #$log->tracef('[comprp] Entering complete_regexp_pattern_pattern(), word=<%s>', $word); | ||||||||||||||||||||||||||||
| 81 | #$log->tracef('[comprp] args=%s', \%args); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # convenience (and compromise): if word doesn't contain :: we use the | ||||||||||||||||||||||||||||
| 84 | # "safer" separator /, but if already contains '::' we use '::'. (Can also | ||||||||||||||||||||||||||||
| 85 | # use '.' if user uses that.) Using "::" in bash means user needs to use | ||||||||||||||||||||||||||||
| 86 | # quote (' or ") to make completion behave as expected since : is by default | ||||||||||||||||||||||||||||
| 87 | # a word break character in bash/readline. | ||||||||||||||||||||||||||||
| 88 | 0 | my $sep = $args{path_sep}; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | unless (defined $sep) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $sep = $word =~ /::/ ? '::' : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 91 | $word =~ /\./ ? '.' : '/'; | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $word =~ s!(::|/|\.)!::!g; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | #$log->tracef('[comprp] invoking complete_path, word=<%s>', $word); | ||||||||||||||||||||||||||||
| 97 | my $res = Complete::Path::complete_path( | ||||||||||||||||||||||||||||
| 98 | word => $word, | ||||||||||||||||||||||||||||
| 99 | starting_path => 'Regexp::Pattern', | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | list_func => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=14 SCAR=51.8
| |||||||||||||||||||||||||||||
| 101 | 0 | my ($path, $intdir, $isint) = @_; | |||||||||||||||||||||||||||
| 102 | 0 | (my $fspath = $path) =~ s!::!/!g; | |||||||||||||||||||||||||||
| 103 | 0 | my @res; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | for my $inc (@INC) { | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | next if ref($inc); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # list .pm files and directories | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $dir = $inc . (length($fspath) ? "/$fspath" : ""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | #say "D:try opendir $dir ..."; | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (opendir my($dh), $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | for my $e (readdir $dh) { | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | next if $e eq '.' || $e eq '..'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e eq "." or $e eq ".."
MC/DC0%0/2
$e eq "." or $e eq ".."
$e eq "."
$e eq ".."
Truth table0%0/3
A or B
A= $e eq "."B= $e eq ".."
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | next unless $e =~ /\A\w+(\.\w+)?\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | my $is_dir = (-d "$dir/$e"); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($is_dir) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 117 | 0 | push @res, "$e\::"; | |||||||||||||||||||||||||||
| 118 | } elsif ($e =~ /(.+)\.pm\z/) { | ||||||||||||||||||||||||||||
| 119 | 0 | push @res, "$1\::"; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # list regexp patterns inside a .pm file | ||||||||||||||||||||||||||||
| 125 | 0 | (my $file = $dir) =~ s!/\z!!; $file .= ".pm"; | |||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | last unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | #say "D:$file is a .pm ..."; | ||||||||||||||||||||||||||||
| 130 | 0 | (my $mod = $path) =~ s/::\z//; | |||||||||||||||||||||||||||
| 131 | 0 | (my $mod_pm = "$mod.pm") =~ s!::!/!g; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | eval { require $mod_pm; 1 } or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my $re = \%{"$mod\::RE"}; | |||||||||||||||||||||||||||
| 134 | 0 | for (keys %$re) { | |||||||||||||||||||||||||||
| 135 | 0 | push @res, $_; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 0 | [sort(uniq(@res))]; | |||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||
| 142 | path_sep => '::', | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | is_dir_func => sub { }, # not needed, we already suffixed "dirs" with :: | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 144 | 0 | ); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | for (@$res) { s/::/$sep/g } | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $res = { words=>$res, path_sep=>$sep }; | |||||||||||||||||||||||||||
| 149 | #$log->tracef('[comprp] Leaving complete_regexp_pattern_pattern(), result=<%s>', $res); | ||||||||||||||||||||||||||||
| 150 | 0 | $res; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1 | 1; | |||||||||||||||||||||||||||
| 154 | # ABSTRACT: Completion routines for Regexp::Pattern | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | __END__ | ||||||||||||||||||||||||||||