4 # For each line in a perl script, write to STDOUT lines of the form
5 # line number : line type : line text
8 # perllinetype myfile.pl >myfile.new
9 # perllinetype <myfile.pl >myfile.new
11 # This file is one of the examples distributed with perltidy and is a
12 # simple demonstration of using a callback object with Perl::Tidy.
14 # Steve Hancock, July 2003
22 usage: perllinetype filename >outfile
24 getopts('h') or die "$usage";
25 if ($opt_h) { die $usage }
27 # Make the source for perltidy, which will be a filehandle
28 # or just '-' if the source is stdin
29 my ($file, $fh, $source);
33 elsif ( @ARGV == 1 ) {
35 $fh = IO::File->new( $file, 'r' );
36 unless ($fh) { die "cannot open '$file': $!\n" }
41 # make the callback object
42 my $formatter = MyFormatter->new();
46 # start perltidy, which will start calling our write_line()
48 'formatter' => $formatter, # callback object
50 'destination' => \$dest, # (not really needed)
51 'argv' => "-npro -se", # dont need .perltidyrc
55 die "Error calling perltidy\n";
68 # This is called from perltidy line-by-line
70 my $line_of_tokens = shift;
71 my $line_type = $line_of_tokens->{_line_type};
72 my $input_line_number = $line_of_tokens->{_line_number};
73 my $input_line = $line_of_tokens->{_line_text};
74 print "$input_line_number:$line_type:$input_line";
77 # called once after the last line of a file
78 sub finish_formatting {