Skip to content

Instantly share code, notes, and snippets.

@kaz-utashiro
Created December 15, 2013 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz-utashiro/7970454 to your computer and use it in GitHub Desktop.
Save kaz-utashiro/7970454 to your computer and use it in GitHub Desktop.
Greple module to handle perl script.
=head1 NAME
perl - Greple module for perl script
=head1 SYNOPSIS
greple -Mperl [ options ]
=head1 SAMPLES
greple -Mperl option pattern
--code search from perl code outisde of pod document
--pod search from pod document
--comment search from comment part
=head1 DESCRIPTION
Sample module for B<greple> command supporting perl script.
=cut
package App::Greple::perl;
use strict;
use warnings;
use Carp;
BEGIN {
use Exporter ();
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
$VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /(\d+)/g;
@ISA = qw(Exporter);
@EXPORT = qw(&pod &comment &podcomment);
%EXPORT_TAGS = ( );
@EXPORT_OK = qw();
}
our @EXPORT_OK;
END { }
my $pod_re = qr{^=\w+(?s:.*?)(?:\Z|^=cut[ \t]*\n)}m;
my $comment_re = qr{^(?:[ \t]*#.*\n)+}m;
sub pod {
my @list;
while (/$pod_re/g) {
push(@list, [ $-[0], $+[0] ] );
}
@list;
}
sub comment {
my @list;
while (/$comment_re/g) {
push(@list, [ $-[0], $+[0] ] );
}
@list;
}
sub podcomment {
my @list;
while (/$pod_re|$comment_re/g) {
push(@list, [ $-[0], $+[0] ] );
}
@list;
}
1;
__DATA__
define :comment: ^([ \t]*#.*\n)+
#define :comment: #.*
define :pod: ^=(?s:.*?)(?:\Z|^=cut[ \t]*\n)
define :podcomment: :pod:|:comment:
option --allsection --pod --comment --code
option --pod --inside :pod:
option --comment --inside :comment:
option --code --outside :podcomment:
#option --pod --inside '&pod'
#option --comment --inside '&comment'
#option --code --outside '&podcomment'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment