File Coverage

blib/lib/App/Greple/perl.pm
Criterion Covered Total %
statement 20 41 48.7
branch 0 6 0.0
condition n/a
subroutine 7 9 77.7
pod 0 2 0.0
total 27 58 46.5


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             perl - Greple module for perl script
4              
5             =head1 SYNOPSIS
6              
7             greple -Mperl [ options ]
8              
9             =head1 SAMPLES
10              
11             greple -Mperl option pattern
12              
13             --code search from perl code outisde of pod document
14             --pod search from pod document
15             --comment search from comment part
16             --data search from data part
17             --doc search from pod and comment
18             --allpart search from all sections
19              
20             greple --colordump file
21              
22             =head1 DESCRIPTION
23              
24             Sample module for B command supporting perl script.
25              
26             =cut
27              
28             package App::Greple::perl;
29              
30 1     1   1064 use v5.24;
  1         3  
31 1     1   4 use warnings;
  1         1  
  1         46  
32 1     1   4 use Carp;
  1         1  
  1         53  
33 1     1   4 use App::Greple::Common;
  1         2  
  1         41  
34 1         68 use App::Greple::Regions qw(
35             REGION_INSIDE REGION_OUTSIDE
36             REGION_UNION REGION_INTERSECT
37             match_regions
38             select_regions
39             merge_regions
40             reverse_regions
41 1     1   4 );
  1         1  
42 1     1   4 use Data::Dumper;
  1         34  
  1         43  
43              
44 1     1   4 use Exporter 'import';
  1         1  
  1         473  
45             our @EXPORT = qw(part pod comment doc code);
46             our %EXPORT_TAGS = ( );
47             our @EXPORT_OK = qw();
48              
49             my %part;
50              
51             my $pod_re = qr{^=\w+(?s:.*?)(?:\z|^=cut\h*\n)}m;
52             my $comment_re = qr{^(?:\h*#.*\n)+}m;
53             my $data_re = qr{^__DATA__\n(?s:.*)}m;
54             my $empty_re = qr{^(?:\h*\n)+}m;
55              
56             sub setup {
57 0     0 0   state $target = -1;
58 0 0         if ($target == \$_) {
59 0           return $target;
60             } else {
61 0           $target = \$_;
62             }
63 0           my @pod = match_regions(pattern => $pod_re);
64 0           my @comment = select_regions([ match_regions(pattern => $comment_re) ],
65             \@pod, REGION_OUTSIDE);
66 0           my @data = match_regions(pattern => $data_re);
67 0           my @empty = match_regions(pattern => $empty_re);
68 0           my @doc = merge_regions(@pod, @comment);
69 0           my @noncode = merge_regions(@doc, @data, @empty);
70 0           my @code = reverse_regions(\@noncode);
71 0           my @nondoc = reverse_regions(\@doc);
72 0           %part = (
73             pod => \@pod,
74             comment => \@comment,
75             doc => \@doc,
76             code => \@code,
77             data => \@data,
78             nondoc => \@nondoc,
79             noncode => \@noncode,
80             empty => \@empty,
81             );
82             }
83              
84             sub part {
85 0     0 0   my %arg = @_;
86 0 0         my $file = delete $arg{&FILELABEL} or die;
87 0 0         setup and merge_regions do {
88 0           map { @{$part{$_}} }
  0            
89 0           grep { exists $part{$_} }
90 0           grep { $arg{$_} }
  0            
91             keys %arg;
92             };
93             }
94              
95             1;
96              
97             __DATA__