Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 84 lines (67 sloc) 2.405 kb
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#!/usr/bin/env perl
use strict;

# This script will recombine the perltidy binary script and all of its
# modules into a single, monolithic script, which is how it was
# originally distributed. It might be useful for users who have
# difficulty installing modules, or prefer not to.

# usage:
# perl pm2pl

# Run this from the perltidy main installation directory. It reads
# bin/perltidy and lib/*.pm and writes a file 'perltidy' in the
# current directory.

# Then, put the file 'perltidy' in your path and it should work (You
# will also need to put the batch file 'perltidy.bat' in your path
# under msdos/windows)

# For unix systems, a sample Makefile is included as Makefile.npm

# This should work for a system with File::Spec,
# and for older Windows/Unix systems without File::Spec.
my $script = 'bin/perltidy';
my $module = 'lib/Perl/Tidy.pm';
eval "use File::Spec;";
my $missing_file_spec = $@;
unless ($missing_file_spec) {
    $script = File::Spec->catfile( 'bin', 'perltidy' );
    $module = File::Spec->catfile( 'lib', 'Perl', 'Tidy.pm' );
}

my $outfile = "perltidy";
open OUTFILE, "> $outfile" or die "can't open file '$outfile' : $!\n";
print "Creating file '$outfile' ....\n ";

# first, open the script and copy the first (hash-bang) line
# (Note: forward slashes in file names here will work in Windows)
open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n";
my $hash_bang = <SCRIPT>;
print OUTFILE $hash_bang;

# then copy all modules (only one for now)
open PM, "< $module" or die "can't open my module file '$module' : $!\n";
while (<PM>) {
    last if /^\s*__END__\s*$/;
    print OUTFILE;
}
close PM;

# then, copy the rest of the script except for the 'use PerlTidy' statement
while (<SCRIPT>) {
    last if /^\s*__END__\s*$/;
    print OUTFILE unless $_ =~ /use Perl::Tidy/;
}
close SCRIPT;
close OUTPUT;
chmod 0755, $outfile;
print "...Done...\n";

my $testfile = "Makefile.PL";
if ( -e $testfile ) {
    print <<EOM;

You can now run perltidy.
For a quick test, try reformatting $testfile with the following command:

perl perltidy -lp $testfile

and then compare the output in $testfile.tdy with the original file
EOM
}
else {
    $testfile = "somefile";
    print <<EOM;

You can now run perltidy to reformat any perl script.
For example, the following command:

perl perltidy $testfile

will produce the output file $testfile.tdy
EOM
}
Something went wrong with that request. Please try again.