4 # This script will recombine the perltidy binary script and all of its modules
5 # into a single, monolithic script. I use it for making a temporary "sandbox"
8 # This is also useful for making a copy of previous versions for parallel
14 # Run this from the perltidy main installation directory. It reads
15 # bin/perltidy and lib/*.pm and writes a file 'perltidy-VERSION.pl' in the
18 # This should work for a system with File::Spec,
19 # and for older Windows/Unix systems without File::Spec.
20 my $script = 'bin/perltidy';
23 lib/Perl/Tidy/Debugger.pm
24 lib/Perl/Tidy/DevNull.pm
25 lib/Perl/Tidy/Diagnostics.pm
26 lib/Perl/Tidy/FileWriter.pm
27 lib/Perl/Tidy/Formatter.pm
28 lib/Perl/Tidy/HtmlWriter.pm
29 lib/Perl/Tidy/IOScalar.pm
30 lib/Perl/Tidy/IOScalarArray.pm
31 lib/Perl/Tidy/IndentationItem.pm
32 lib/Perl/Tidy/LineBuffer.pm
33 lib/Perl/Tidy/LineSink.pm
34 lib/Perl/Tidy/LineSource.pm
35 lib/Perl/Tidy/Logger.pm
36 lib/Perl/Tidy/Tokenizer.pm
37 lib/Perl/Tidy/VerticalAligner.pm
38 lib/Perl/Tidy/VerticalAligner/Alignment.pm
39 lib/Perl/Tidy/VerticalAligner/Line.pm
42 # try to make the pathnames system independent
43 eval "use File::Spec;";
44 my $missing_file_spec = $@;
45 unless ($missing_file_spec) {
46 $script = File::Spec->catfile( split '/', $script );
47 foreach my $module (@modules) {
48 $module = File::Spec->catfile( split '/', $module );
52 my $VERSION = get_version("lib/Perl/Tidy.pm");
53 my $outfile = "perltidy-$VERSION.pl";
54 open OUTFILE, "> $outfile" or die "can't open file '$outfile' : $!\n";
55 print "Creating standalone formatter script '$outfile' ....\n ";
57 # first, open the script and copy the first (hash-bang) line
58 # (Note: forward slashes in file names here will work in Windows)
59 open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n";
60 my $hash_bang = <SCRIPT>;
61 print OUTFILE $hash_bang;
63 # then copy all modules
64 foreach my $module (@modules) {
65 open PM, "< $module" or die "can't open my module file '$module' : $!\n";
67 last if /^\s*__END__\s*$/;
68 print OUTFILE unless $_ =~ /^use Perl::Tidy/;
73 # then, copy the rest of the script except for the 'use PerlTidy' statement
75 last if /^\s*__END__\s*$/;
76 print OUTFILE unless $_ =~ /^use Perl::Tidy/;
82 my $testfile = "somefile.pl";
85 You can now run $outfile to reformat perl scripts.
86 For example, the following command:
88 perl $outfile $testfile
90 will produce the output file $testfile.tdy
96 open( $fh, "<", $file ) || die "cannot open $fh: $!\n";
97 while ( my $line = <$fh> ) {
99 # Looking for something simple like this, with or without quotes,
100 # with semicolon and no sidecomments:
101 # $VERSION = "20180202.245" ;
102 # our $VERSION = 20104202 ;
104 /^((our)?\s*\$VERSION\s*=\s*\'?) ([^'#]+) (\'?) \s* ;/x )