Data-Locations
view release on metacpan or search on metacpan
Locations.pm view on Meta::CPAN
data in a particular order, but that some piece of the data was still
unavailable at the point in the sequence where it belonged and where
it should have been produced?
Did you also have to resort to cumbersome and tedious measures such
as storing the first and the last part of your data separately, then
producing the missing middle part, and finally putting it all together?
In this simple case, involving only one deferred insertion, you might
still put up with this solution.
But if there is more than one deferred insertion, requiring the handling
of many fragments of data, you will probably get annoyed and frustrated.
You might even have to struggle with limitations of the file system of
your operating system, or handling so many files might considerably slow
down your application due to excessive file input/output.
And if you don't know exactly beforehand how many deferred insertions
there will be (if this depends dynamically on the data being processed),
and/or if the pieces of data you need to insert need additional (nested)
insertions themselves, things will get really tricky, messy and troublesome.
In such a case you might wonder if there wasn't an elegant solution to
this problem.
This is where the "C<Data::Locations>" module comes in: It handles such
insertion points automatically for you, no matter how many and how deeply
nested, purely in memory, requiring no (inherently slower) file input/output
operations.
(The underlying operating system will automatically take care if the amount
of data becomes too large to be handled fully in memory, though, by swapping
out unneeded parts.)
Moreover, it also allows you to insert the same fragment of data into
SEVERAL different places.
This increases space efficiency because the same data is stored in
memory only once, but used multiple times.
Potential infinite recursion loops are detected automatically and
refused.
In order to better understand the underlying concept, think of
"C<Data::Locations>" as virtual files with almost random access:
You can write data to them, you can say "reserve some space here
which I will fill in later", and continue writing data.
And you can of course also read from these virtual files, at any time,
in order to see the data that a given virtual file currently contains.
When you are finished filling in all the different parts of your virtual
file, you can write out its contents in flattened form to a physical, real
file this time, or process it otherwise (purely in memory, if you wish).
You can also think of "C<Data::Locations>" as bubbles and bubbles inside
of other bubbles. You can inflate these bubbles in any arbitrary order
you like through a straw (i.e., the bubble's object reference).
Note that this module handles your data completely transparently, which
means that you can use it equally well for text AND binary data.
You might also be interested in knowing that this module and its concept
have already been heavily used in the automatic code generation of large
software projects.
=head1 SYNOPSIS
use Data::Locations;
new
$toplocation = Data::Locations->new();
$toplocation = Data::Locations->new($filename);
$sublocation = $location->new();
$sublocation = $location->new($filename);
filename
$location->filename($filename);
$filename = $location->filename();
$oldfilename = $location->filename($newfilename);
toplevel
$flag = $location->toplevel();
print
$location->print(@items);
print $location @items;
printf
$location->printf($format, @items);
printf $location $format, @items;
println
$location->println(@items);
read
$item = $location->read();
$item = <$location>;
@list = $location->read();
@list = <$location>;
reset
$location->reset();
traverse
$location->traverse(\&callback_function);
dump
$ok = $location->dump();
$ok = $location->dump($filename);
delete
$location->delete();
tie
$location->tie('FILEHANDLE');
$location->tie(*FILEHANDLE);
$location->tie(\*FILEHANDLE);
$location->tie(*{FILEHANDLE});
$location->tie(\*{FILEHANDLE});
( run in 2.166 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )