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

NAME

File::Mosaic - assemble the constituent pieces of a file into a single file.

SYNOPSIS

 use File::Mosaic;

 my $m = File::Mosaic->new(filename         => "/etc/dhcpd.conf", 
                           mosaic_directory => "/etc/dhcpd.conf.mosaic");

 $m->append(tag => 'begin', mosaic => "# dhcpd.conf\n");

 my $subnet;
 $subnet .= "subnet 192.168.1.1 netmask 255.255.255.0 {\n";
 $subnet .= "    option routers 192.168.1.1;\n";
 $subnet .= "    range 192.168.1.100 192.168.1.254;\n";
 $subnet .= "}\n\n";

 $m->append(tag => 'subnet1', mosaic => $subnet);
 $m->append(tag => 'begin', mosaic => "# dhcpd.conf\n");

 my $host;
 $host .= "host test {\n";
 $host .= "    hardware ethernet ff:ff:ee:00:00:01;\n";
 $host .= "    fixed-address 192.168.1.25;\n";
 $host .= "}\n";

 $m->insert_after(tag => 'host1', after_tag => 'subnet1', mosaic => $host);
 $m->close();

DESCRIPTION

File::Mosaic is a Perl module to assemble a target file from smaller files. The creation, maintenance, and order of the small files, as well as the assembling of the target file are handled by the library. Data for the small files are added by the user along with a tag. The tags are used to determine position within the target file. Users have the ability to add data before, or after a tag, as well as at the end of the file. Tags can be removed, and the data attached to a tag can be fetchied using the methods of the class.

The motivation for creating this library was due to all of the auto-generated files I have to deal with. The files almost always have a static header, and footer, but with some piece of data constantly being added and or removed from the middle. Updating a single entry would require the entire regeneration of the file, but unfortunatley I can't always guarantee the state of the entries at the time of regeneration. Ideally, I just want to update my entry, and my entry only.

METHODS

new
append(tag, mosaic)

Append the tag, and mosaic to the end of the file.

insert_before(tag, before_tag, mosaic)

Insert the tag, and mosaic before the tag before_tag.

insert_after(tag, after_tag, mosaic)

Insert the tag, and mosaic after the tag after_tag.

replace(tag, mosaic)

Replace the mosaic at tag, with the user supplied mosaic.

remove(tag)

Remove the tag from the file.

fetch(tag)

Return the mosaic located at the tag.

fetch_tags()

Return an array or array ref of all of the current tags.

reorder_tags(tags)

Use the tags array to reorder the position of the current tags. The position in the array determines the position of the tags. The tag at index 0 of tags it put at the beginning of the file. Likewise the tag at index -1 of tags it put at the end of the file.

close

Close the mosaic file, save all of the tag and mosaic information, and reconstruct the file based on the current information.

AUTHORS

Christopher Boumenot <boumenot@gmail.com>