7 This script will recombine the perltidy binary script and all of its modules
8 into a single, monolithic script.
10 Run this from the perltidy main installation directory. It reads
11 bin/perltidy and lib/*.pm and by default writes a file 'perltidy-VERSION.pl' in the
15 perl pm2pl [-h -o ofile ]
18 -o set output file [ default is 'perltidy-VERSION.pl' ]
19 -D set DEVEL_MODE => 1 [ for extra testing when debugging ]
22 my @option_string = qw(
29 if ( !GetOptions( \%Opts, @option_string ) ) {
30 die "Programming Bug: error in setting default options";
38 # This should work for a system with File::Spec,
39 # and for older Windows/Unix systems without File::Spec.
40 my $script = 'bin/perltidy';
43 lib/Perl/Tidy/Debugger.pm
44 lib/Perl/Tidy/DevNull.pm
45 lib/Perl/Tidy/Diagnostics.pm
46 lib/Perl/Tidy/FileWriter.pm
47 lib/Perl/Tidy/Formatter.pm
48 lib/Perl/Tidy/HtmlWriter.pm
49 lib/Perl/Tidy/IOScalar.pm
50 lib/Perl/Tidy/IOScalarArray.pm
51 lib/Perl/Tidy/IndentationItem.pm
52 lib/Perl/Tidy/LineBuffer.pm
53 lib/Perl/Tidy/LineSink.pm
54 lib/Perl/Tidy/LineSource.pm
55 lib/Perl/Tidy/Logger.pm
56 lib/Perl/Tidy/Tokenizer.pm
57 lib/Perl/Tidy/VerticalAligner.pm
58 lib/Perl/Tidy/VerticalAligner/Alignment.pm
59 lib/Perl/Tidy/VerticalAligner/Line.pm
62 # try to make the pathnames system independent
63 eval "use File::Spec;";
64 my $missing_file_spec = $@;
65 unless ($missing_file_spec) {
66 $script = File::Spec->catfile( split '/', $script );
67 foreach my $module (@modules) {
68 $module = File::Spec->catfile( split '/', $module );
72 my $VERSION = get_version("lib/Perl/Tidy.pm");
73 my $outfile = "perltidy-$VERSION.pl";
74 if ( $Opts{o} ) { $outfile = $Opts{o} }
76 open( $fh_out, ">", $outfile ) or die "can't open file '$outfile' : $!\n";
77 print "Creating standalone perltidy script '$outfile' ....";
79 # first, open the script and copy the first (hash-bang) line
80 # (Note: forward slashes in file names here will work in Windows)
82 open( $fh_in, "<", $script ) or die "can't open script file '$script' : $!\n";
83 my $hash_bang = <$fh_in>;
84 $fh_out->print($hash_bang);
86 # then copy all modules
88 foreach my $module (@modules) {
90 open( $fh_module, '<', $module )
91 or die "can't open my module file '$module' : $!\n";
92 while (<$fh_module>) {
93 last if /^\s*__END__\s*$/;
97 /^(\s*use\s+constant\s+(?:DEVEL)_[A-Z]+\s*)=>\s*(-?\d*);(.*)$/ )
107 $fh_out->print($line) unless $line =~ /^use Perl::Tidy/;
112 # then, copy the rest of the script except for the 'use PerlTidy' statement
114 last if /^\s*__END__\s*$/;
115 $fh_out->print($_) unless $_ =~ /^use Perl::Tidy/;
119 chmod 0755, $outfile;
122 if ($changed_count) {
124 $changed_count lines changed to DEVEL_MODE => 1
131 open( $fh, "<", $file ) || die "cannot open $fh: $!\n";
132 while ( my $line = <$fh> ) {
134 # Looking for something simple like this, with or without quotes,
135 # with semicolon and no sidecomments:
136 # $VERSION = "20180202.245" ;
137 # our $VERSION = 20104202 ;
139 /^((our)?\s*\$VERSION\s*=\s*\'?) ([^'#]+) (\'?) \s* ;/x )