The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

File::Mangle - Perl module for file manipulation

SYNOPSIS

  use File::Mangle qw(replace_block);

  replace_block('/etc/sudoers', 'automanaged', "martyn ALL=(ALL) ALL");

  my $data = fetch_block('/etc/sudoers', 'automanaged');

DESCRIPTION

A collection of utilities designed to make programmatic editing of configuration files nice and simple.

EXPORT

None by default.

FUNCTIONS

fetch_block(filename, marker)

Performs the returning existing block part of the replace_block() function below without altering the file in any way.

replace_block(filename, marker, replacement, line-comment-marker)

Edits the file filename adding start and end markers if they're not already there. Once the markers are in place, it replaces everything between the markers with replacement.

line-comment-marker defaults to '#' (which is prefixed to the markers to ensure they don't intefere with the purpose of the file).

This function returns the data that was in the block prior to the replacement.

insert_block_before(filename, marker, placement, line-comment-marker)

Edits the file filename adding start and end markers if they're not already there.

The placement parameter is a regexp fragment which File::Mangle uses to find a line in the target file to insert the markers before

line-comment-marker defaults to '#' (which is prefixed to the markers to ensure they don't intefere with the purpose of the file).

This function returns nothing if the block already exists or it was unable to find the placement regexp, and it returns 1 on success

insert_block_after(filename, marker, placement, line-comment-marker)

This function operates exactly like insert_block_before with the exception of putting the markers after the placement match instead of before.

AUTHOR

Martyn Smith, <martyn@dollyfish.net.nz>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Martyn Smith

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.