ActiveState::Indenter - Keep track of indentation levels
use ActiveState::Indenter;
my $fh = ActiveState::Indenter->new(*STDOUT); $fh->print("if (foo()) {\n") $fh->over; $fh->print("# do something\n"); $fh->back; $fh->print("}\n");
The ActiveState::Indenter works like an output file handle but will insert whitespace in the printed stream reflecting the current indentation level. It is useful for printing out nicely formatted programs.
The following methods are available:
The object constructor takes a file handle as argument. It will create a new indenter object that prints to the given file handle.
The $filehandle can actually be any object that implement a print()
method.
Returns back the filehandle passed to the constructor.
This get/set the current line width. The line width is used by the
soft_space()
method. The default is 70.
This get/set the standard indentation offset. The default is 4.
The print()
will print the string given as argument to the wrapped
file handle but with suitable additional leading space added. The
indenter object will never buffer output, so all content of the string
will have reached the file when print returns.
This will print a space character " " if there is more room on the line, or a newline otherwise.
This returns the current indentation column.
This increase the indentation column with the given amount. Without argument the standard amount is used.
This sets the indentation column the same as the current column.
This set the indentation column to the number given.
Returns to the previous indentation column.
Returns the current column position.
This get/set the current line number.
Returns the current indentation depth.
Copyright (C) 2003 ActiveState Corp. All rights reserved.