ActiveState::Indenter - Keep track of indentation levels


ActiveState::Indenter - Keep track of indentation levels


 use ActiveState::Indenter;
 my $fh = ActiveState::Indenter->new(*STDOUT);
 $fh->print("if (foo()) {\n")
 $fh->print("# do something\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:

$fh = ActiveState::Indenter->new( $filehandle )

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.

$fh->line_width( $new_width )

This get/set the current line width. The line width is used by the soft_space() method. The default is 70.

$fh->indent_offset( $new_offset )

This get/set the standard indentation offset. The default is 4.

$fh->print( $string )

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.

$col = $fh->indent

This returns the current indentation column.

$fh->over( $offset )

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.

$fh->over_abs( $col )

This set the indentation column to the number given.


Returns to the previous indentation column.

$col = $fh->column

Returns the current column position.

$line = $fh->line
$fh->line( $new_line )

This get/set the current line number.

$n = $fh->depth

Returns the current indentation depth.


Copyright (C) 2003 ActiveState Corp. All rights reserved.


Hey! The above document had some coding errors, which are explained below:

Around line 220:

You forgot a '=back' before '=head1'