use strict;
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 ";
open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n";
my $hash_bang = <SCRIPT>;
print OUTFILE $hash_bang;
open PM, "< $module" or die "can't open my module file '$module' : $!\n";
while (<PM>) {
last if /^\s*__END__\s*$/;
print OUTFILE;
}
close PM;
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
}