]> git.donarmstrong.com Git - perltidy.git/blob - examples/ex_mp.pl
New upstream version 20181120
[perltidy.git] / examples / ex_mp.pl
1 #!/usr/bin/perl -w
2
3 # example call to perltidy from man page documentation of Perl::Tidy
4
5 use strict;
6 use Perl::Tidy;
7
8 my $source_string = <<'EOT';
9 my$error=Perl::Tidy::perltidy(argv=>$argv,source=>\$source_string,
10     destination=>\$dest_string,stderr=>\$stderr_string,
11 errorfile=>\$errorfile_string,);
12 EOT
13
14 my $dest_string;
15 my $stderr_string;
16 my $errorfile_string;
17 my $argv = "-npro";   # Ignore any .perltidyrc at this site
18 $argv .= " -pbp";     # Format according to perl best practices
19 $argv .= " -nst";     # Must turn off -st in case -pbp is specified
20 $argv .= " -se";      # -se appends the errorfile to stderr
21 ## $argv .= " --spell-check";  # uncomment to trigger an error
22
23 print "<<RAW SOURCE>>\n$source_string\n";
24
25 my $error = Perl::Tidy::perltidy(
26     argv        => $argv,
27     source      => \$source_string,
28     destination => \$dest_string,
29     stderr      => \$stderr_string,
30     errorfile   => \$errorfile_string,    # not used when -se flag is set
31     ##phasers     => 'stun',                # uncomment to trigger an error
32 );
33
34 if ($error) {
35
36     # serious error in input parameters, no tidied output
37     print "<<STDERR>>\n$stderr_string\n";
38     die "Exiting because of serious errors\n";
39 }
40
41 if ($dest_string)      { print "<<TIDIED SOURCE>>\n$dest_string\n" }
42 if ($stderr_string)    { print "<<STDERR>>\n$stderr_string\n" }
43 if ($errorfile_string) { print "<<.ERR file>>\n$errorfile_string\n" }