]> git.donarmstrong.com Git - perltidy.git/blob - pm2pl
[svn-inject] Installing original source of perltidy
[perltidy.git] / pm2pl
1 #!/usr/bin/env perl
2 use strict;
3
4 # This script will recombine the perltidy binary script and all of its
5 # modules into a single, monolithic script, which is how it was
6 # originally distributed.  It might be useful for users who have
7 # difficulty installing modules, or prefer not to.
8
9 # usage:
10 #   perl pm2pl
11
12 # Run this from the perltidy main installation directory.  It reads
13 # bin/perltidy and lib/*.pm and writes a file 'perltidy' in the
14 # current directory.
15
16 # Then, put the file 'perltidy' in your path and it should work (You
17 # will also need to put the batch file 'perltidy.bat' in your path
18 # under msdos/windows)
19
20 # For unix systems, a sample Makefile is included as Makefile.npm
21
22 # This should work for a system with File::Spec,
23 # and for older Windows/Unix systems without File::Spec.
24 my $script = 'bin/perltidy';
25 my $module = 'lib/Perl/Tidy.pm';
26 eval "use File::Spec;";
27 my $missing_file_spec = $@;
28 unless ($missing_file_spec) {
29     $script = File::Spec->catfile( 'bin', 'perltidy' );
30     $module = File::Spec->catfile( 'lib', 'Perl', 'Tidy.pm' );
31 }
32
33 my $outfile = "perltidy";
34 open OUTFILE, "> $outfile" or die "can't open file '$outfile' : $!\n";
35 print "Creating file '$outfile' ....\n ";
36
37 # first, open the script and copy the first (hash-bang) line
38 # (Note: forward slashes in file names here will work in Windows)
39 open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n";
40 my $hash_bang = <SCRIPT>;
41 print OUTFILE $hash_bang;
42
43 # then copy all modules (only one for now)
44 open PM, "< $module" or die "can't open my module file '$module' : $!\n";
45 while (<PM>) {
46     last if /^\s*__END__\s*$/;
47     print OUTFILE;
48 }
49 close PM;
50
51 # then, copy the rest of the script except for the 'use PerlTidy' statement
52 while (<SCRIPT>) {
53     last if /^\s*__END__\s*$/;
54     print OUTFILE unless $_ =~ /use Perl::Tidy/;
55 }
56 close SCRIPT;
57 close OUTPUT;
58 chmod 0755, $outfile;
59 print "...Done...\n";
60
61 my $testfile = "Makefile.PL";
62 if ( -e $testfile ) {
63     print <<EOM;
64
65 You can now run perltidy. 
66 For a quick test, try reformatting $testfile with the following command:
67
68     perl perltidy -lp $testfile
69
70 and then compare the output in $testfile.tdy with the original file
71 EOM
72 }
73 else {
74     $testfile = "somefile";
75     print <<EOM;
76
77 You can now run perltidy to reformat any perl script.  
78 For example, the following command:
79
80     perl perltidy $testfile
81
82 will produce the output file $testfile.tdy
83 EOM
84 }