Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 83 lines (68 sloc) 2.088 kb
#!perl
# Squashes together the parts of ack into the single ack app.
use warnings;
use strict;
use File::Next;
# make clear that ack is not supposed to be edited
my $NO_EDIT_COMMENT = <<'EOCOMMENT';
#
# This file, ack, is generated code.
# Please DO NOT EDIT or send patches for it.
#
# Please take a look at the source from
# http://github.com/petdance/ack2
# and submit patches against the individual files
# that build ack.
#
EOCOMMENT
my $debug_mode = grep { $_ eq '--debug' } @ARGV;
@ARGV = grep { $_ ne '--debug' } @ARGV;
my $code;
for my $arg ( @ARGV ) {
my $filename = $arg;
if ( $arg =~ /::/ ) {
my $key = "$arg.pm";
$key =~ s{::}{/}g;
$filename = $INC{$key} or die "Can't find the file for $arg";
}
warn "Reading $filename\n";
open( my $fh, '<', $filename ) or die "Can't open $filename: $!";
my $was_in_pod = 0;
my $in_pod = 0;
$code .= "#line 1 '$filename'\n" if $debug_mode && $filename ne 'ack-base';
while ( <$fh> ) {
next if /^use (?:File::Next|App::Ack)/;
s/^use base (.+)/BEGIN {\n our \@ISA = $1\n}/;
if ( $was_in_pod && !$in_pod ) {
$was_in_pod = 0;
if ($debug_mode) {
$code .= "#line $. '$filename'\n";
}
}
# See if we're in module POD blocks
if ( $filename ne 'ack-base' ) {
$was_in_pod = $in_pod;
if ( /^=(\w+)/ ) {
$in_pod = ($1 ne 'cut');
next;
}
elsif ( $in_pod ) {
next;
}
}
# Replace the shebang line and append 'no edit' comment
if ( s{^#!.+}{#!/usr/bin/env perl} ) {
$_ .= $NO_EDIT_COMMENT;
}
# Remove Perl::Critic comments.
# I'd like to remove all comments, but this is a start
s{\s*##.+critic.*}{};
$code .= $_;
}
close $fh;
}
for my $unused_func ( qw( dirs everything ) ) {
$code =~ s/^sub $unused_func\b.*?^}//sm; # It's OK if we can't find it
}
print $code;
exit 0;
Jump to Line
Something went wrong with that request. Please try again.