| 1 | ## no critic: InputOutput::RequireBriefOpen | ||
| 2 | |||
| 3 | package App::wcgrep; | ||
| 4 | |||
| 5 | 1 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Log::ger; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use AppBase::Grep; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use AppBase::Grep::File (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use Perinci::Sub::Util qw(gen_modified_sub); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 15 | 1 | our $DATE = '2023-11-17'; # DATE | |
| 16 | 1 | our $DIST = 'App-wcgrep'; # DIST | |
| 17 | 1 | our $VERSION = '0.002'; # VERSION | |
| 18 | |||
| 19 | 1 | our %SPEC; | |
| 20 | |||
| 21 | gen_modified_sub( | ||
| 22 | output_name => 'wcgrep', | ||
| 23 | base_name => 'AppBase::Grep::grep', | ||
| 24 | summary => 'Print lines matching a wildcard pattern', | ||
| 25 | description => <<'_', | ||
| 26 | |||
| 27 | This is another grep-like utility that is based on <pm:AppBase::Grep>, mainly | ||
| 28 | for demoing and testing the module. It accepts bash wildcard pattern instead of | ||
| 29 | regular expression. | ||
| 30 | |||
| 31 | _ | ||
| 32 | add_args => { | ||
| 33 | %AppBase::Grep::File::argspecs_files, | ||
| 34 | }, | ||
| 35 | 1 | ▶ | modify_meta => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 36 | 1 | my $meta = shift; | |
| 37 | |||
| 38 | # modify arg | ||
| 39 | $meta->{args}{pattern} = { | ||
| 40 | 1 | summary => 'Specify *wildcard pattern* to search for', | |
| 41 | schema => 'str*', | ||
| 42 | req => 1, | ||
| 43 | pos => 0, | ||
| 44 | }; | ||
| 45 | |||
| 46 | # delete args | ||
| 47 | 1 | delete $meta->{args}{regexps}; | |
| 48 | 1 | delete $meta->{args}{dash_prefix_inverts}; | |
| 49 | 1 | delete $meta->{args}{all}; | |
| 50 | |||
| 51 | $meta->{examples} = [ | ||
| 52 | { | ||
| 53 | 1 | summary => 'Show lines that contain foo and bar, in that order', | |
| 54 | 'src' => q([[prog]] 'foo*bar' file1 file2), | ||
| 55 | 'src_plang' => 'bash', | ||
| 56 | 'test' => 0, | ||
| 57 | 'x.doc.show_result' => 0, | ||
| 58 | }, | ||
| 59 | ]; | ||
| 60 | $meta->{links} = [ | ||
| 61 | 1 | {url=>'prog:abgrep'}, | |
| 62 | ]; | ||
| 63 | }, | ||
| 64 | 0 | ▶ | output_code => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 65 | 0 | my %args = @_; | |
| 66 | |||
| 67 | # convert wildcard pattern to regex | ||
| 68 | 0 | my $pat = delete $args{pattern}; | |
| 69 | 0 | require String::Wildcard::Bash; | |
| 70 | 0 | my $re = String::Wildcard::Bash::convert_wildcard_to_re($pat); | |
| 71 | 0 | $args{regexps} = [$re]; | |
| 72 | |||
| 73 | 0 | AppBase::Grep::File::set_source_arg(\%args); | |
| 74 | 0 | AppBase::Grep::grep(%args); | |
| 75 | }, | ||
| 76 | 1 | ); | |
| 77 | |||
| 78 | 1 | 1; | |
| 79 | # ABSTRACT: Print lines matching a wildcard pattern | ||
| 80 | |||
| 81 | __END__ | ||