File: squash

package info (click to toggle)
ack-grep 1.80-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 680 kB
  • ctags: 161
  • sloc: perl: 4,715; ansic: 21; fortran: 11; makefile: 9
file content (46 lines) | stat: -rwxr-xr-x 1,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!perl

# Quickie utility for squashing together the parts for the standalone version

use warnings;
use strict;

use File::Next;

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: $!";

    while ( <$fh> ) {
        next if /^use (File::Next|App::Ack)/;

        # See if we're in module POD blocks
        my $skip = ($filename ne 'ack') && (/^=/ .. /^=cut/);
        if ( !$skip ) {
            # Replace the shebang line
            s{^#!.+}{#!/usr/bin/env perl};

            # 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;