NAME

Perl::Tidy - main module for the perltidy utility

SYNOPSIS

use Perl::Tidy;

Perl::Tidy::perltidy(
    source      => $source,
    destination => $destination,
    stderr      => $stderr,
    argv        => $argv,
    perltidyrc  => $perltidyrc,
    logfile     => $logfile,
    errorfile   => $errorfile,
);

DESCRIPTION

This module makes the functionality of the perltidy utility available to perl scripts. Any or all of the input parameters may be omitted, in which case the @ARGV array will be used to provide input parameters as described in the perltidy(1) man page.

For example, the perltidy script is basically just this:

use Perl::Tidy;
Perl::Tidy::perltidy();

The module accepts input and output streams by a variety of methods. The following list of parameters may be any of a the following: a filename, an ARRAY reference, a SCALAR reference, or an object with either a getline or print method, as appropriate.

source          - the source of the script to be formatted
destination     - the destination of the formatted output
stderr          - standard error output
perltidyrc      - the .perltidyrc file
logfile         - the .LOG file stream, if any 
errorfile       - the .ERR file stream, if any

The following chart illustrates the logic used to decide how to treat a parameter.

ref($param)  $param is assumed to be:
-----------  ---------------------
undef        a filename
SCALAR       ref to string
ARRAY        ref to array
(other)      object with getline (if source) or print method

If the parameter is an object, and the object has a close method, that close method will be called at the end of the stream.

source

If the source parameter is given, it defines the source of the input stream.

destination

If the destination parameter is given, it will be used to define the file or memory location to receive output of perltidy.

stderr

The stderr parameter allows the calling program to capture the output to what would otherwise go to the standard error output device.

perltidyrc

If the perltidyrc file is given, it will be used instead of any .perltidyrc configuration file that would otherwise be used.

argv

If the argv parameter is given, it will be used instead of the @ARGV array. The argv parameter may be a string, a reference to a string, or a reference to an array. If it is a string or reference to a string, it will be parsed into an array of items just as if it were a command line string.

EXAMPLE

The following example passes perltidy a snippet as a reference to a string and receives the result back in a reference to an array.

use Perl::Tidy;

# some messy source code to format
my $source = <<'EOM';
use strict;
my @editors=('Emacs', 'Vi   '); my $rand = rand();
print "A poll of 10 random programmers gave these results:\n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $editors[$i] users are from Venus" . ", " . 
"$editors[1-$i] users are from Mars" . 
"\n";
}
EOM

# We'll pass it as ref to SCALAR and receive it in a ref to ARRAY
my @dest;
perltidy( source => \$source, destination => \@dest );
foreach (@dest) {print}

EXPORT

&perltidy

CREDITS

Thanks to Hugh Myers who developed the initial modular interface to perltidy.

VERSION

This man page documents Perl::Tidy version 20021130.

AUTHOR

Steve Hancock
perltidy at users.sourceforge.net

SEE ALSO

The perltidy(1) man page describes all of the features of perltidy. It can be found at http://perltidy.sourceforge.net.