line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
App::Greple::xp - extended pattern module |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Version 0.04 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
greple -Mxp |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This module provides functions those can be used by B pattern |
16
|
|
|
|
|
|
|
and region options. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 OPTIONS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over 7 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=item B<--le-pattern> I |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=item B<--inside-pattern> I |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item B<--outside-pattern> I |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item B<--include-pattern> I |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item B<--exclude-pattern> I |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Read file contents and use each lines as a pattern for options. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item B<--le-string> I |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item B<--inside-string> I |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item B<--outside-string> I |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B<--include-string> I |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item B<--exclude-string> I |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Almost same as B<*-pattern> option but each line is concidered as a |
45
|
|
|
|
|
|
|
fixed string rather than regular expression. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 COMMENT |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Lines start with hash mark (C<#>) is ignored as a comment line. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
String after double slash (C/>) is also ignored with preceding |
54
|
|
|
|
|
|
|
spaces. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 WILD CARD |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Because I parameter is globbed, you can use wild card to give |
59
|
|
|
|
|
|
|
multiple files. If nothing matched to the wild card, this option is |
60
|
|
|
|
|
|
|
simply ignored with no message. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$ greple -Mxp --exclude-pattern '*.exclude' ... |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Kazumasa Utashiro |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 LICENSE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Copyright 2019- Kazumasa Utashiro. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
79
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
package App::Greple::xp; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
1
|
|
900
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
87
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
88
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
1
|
|
68
|
use Exporter 'import'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
78
|
|
93
|
|
|
|
|
|
|
our @EXPORT = qw(&xp_pattern_file); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
|
674
|
use open IO => ':utf8'; |
|
1
|
|
|
|
|
1304
|
|
|
1
|
|
|
|
|
6
|
|
96
|
1
|
|
|
1
|
|
616
|
use App::Greple::Common; |
|
1
|
|
|
|
|
386
|
|
|
1
|
|
|
|
|
140
|
|
97
|
1
|
|
|
1
|
|
508
|
use App::Greple::Regions qw(match_regions merge_regions); |
|
1
|
|
|
|
|
10846
|
|
|
1
|
|
|
|
|
74
|
|
98
|
1
|
|
|
1
|
|
12
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
421
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @default_opt = ( |
101
|
|
|
|
|
|
|
hash_comment => 1, |
102
|
|
|
|
|
|
|
slash_comment => 1, |
103
|
|
|
|
|
|
|
glob => 1, |
104
|
|
|
|
|
|
|
fixed => 0, |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub xp_pattern_file { |
108
|
0
|
|
|
0
|
0
|
|
my %opt = (@default_opt, @_); |
109
|
0
|
0
|
|
|
|
|
my $target = delete $opt{&FILELABEL} or die; |
110
|
0
|
|
|
|
|
|
my $file = $opt{file}; |
111
|
0
|
0
|
|
|
|
|
my @files = $opt{glob} ? glob $file : ($file); |
112
|
0
|
|
|
|
|
|
my @r; |
113
|
0
|
|
|
|
|
|
for my $file (@files) { |
114
|
0
|
0
|
|
|
|
|
open my $fh, $file or die "$file: $!"; |
115
|
0
|
|
|
|
|
|
while (my $p = <$fh>) { |
116
|
0
|
|
|
|
|
|
chomp $p; |
117
|
0
|
0
|
0
|
|
|
|
if ($opt{hash_comment} and !$opt{fixed}) { |
118
|
0
|
0
|
|
|
|
|
next if $p =~ /^\s*#/; |
119
|
|
|
|
|
|
|
} |
120
|
0
|
0
|
0
|
|
|
|
if ($opt{slash_comment} and !$opt{fixed}) { |
121
|
0
|
|
|
|
|
|
$p =~ s{\s*//.*}{}; |
122
|
|
|
|
|
|
|
} |
123
|
0
|
0
|
|
|
|
|
next unless $p =~ /\S/; |
124
|
0
|
0
|
|
|
|
|
my $re = $opt{fixed} ? qr/\Q$p/ : qr/$p/m; |
125
|
0
|
|
|
|
|
|
push @r, match_regions pattern => $re; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
merge_regions @r; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__DATA__ |