Goo::Thing::pm::PerlTidyManager - Tidy up a Perl program using PerlTidy


Goo documentation Contained in the Goo distribution.

Index


Code Index:

NAME

Top

Goo::Thing::pm::PerlTidyManager - Tidy up a Perl program using PerlTidy

SYNOPSIS

Top

use Goo::Thing::pm::PerlTidyManager;

DESCRIPTION

Top

METHODS

Top

process

tidy up a file after we've finished editing it

AUTHOR

Top

Nigel Hamilton <nigel@trexy.com>

SEE ALSO

Top

Perl::Tidy


Goo documentation Contained in the Goo distribution.

package Goo::Thing::pm::PerlTidyManager;

###############################################################################
# Nigel Hamilton
#
# Copyright Nigel Hamilton 2005
# All Rights Reserved
#
# Author:       Nigel Hamilton
# Filename:     Goo::Thing::pm::PerlTidyManager
# Description:  Tidy up a Perl program - make sure the indentation is correct
#               The tidy parameters are set on a per directory basis in the
#              	perltidyrc file - if there is not one in the current directory
#               it looks in the home directory of the current user.
#               Update the perltidyrc file to change the main parts of perltidy.
#               The format is based on the Best Practices written by Damian
#               Conway - "Perl Best Practices"..
#
# Date          Change
# -----------------------------------------------------------------------------
# 05/09/2005    Auto generated file
# 05/09/2005    Needed to wrap the Perl Tidy utility with my own options
#
###############################################################################

use strict;

use Perl::Tidy;
use Goo::Prompter;
use Goo::TabConverter;
use Goo::FileUtilities;


###############################################################################
#
# process - tidy a file
#
###############################################################################

sub process {

    my ($filename) = @_;

    unless ( -e $filename ) {
        die("$filename does not exist. Unable to tidy.");
    }

    my $tidy_file = $filename . ".tdy";

    # call perltidy on the file
    `perltidy -pro='$ENV{HOME}/.goo/perltidyrc' $filename > $tidy_file`;

    unless ( -e $tidy_file ) {
        Goo::Prompter::notify("perltidy failed to generate $tidy_file");
        exit;
    }

    # add an extra space between subs
    # $file =~ s/^\}/\}\n/gms;

    my @tidier_lines;

    foreach my $line (Goo::FileUtilities::get_file_as_lines($tidy_file)) {
    
        # find any tabs in comments
        if ($line =~ /^\#.*\t/) {

			# convert tabs to 4 spaces
            $line = Goo::TabConverter::tabs_to_spaces($line, 4);
        }

        push(@tidier_lines, $line);        

    }

    Goo::FileUtilities::write_lines_as_file($filename, @tidier_lines);

    # remove the .tdy file
    unlink($tidy_file);

}

1;


__END__