
LBS::2D::Sparse - a 2D storage, using sparse hash

my $storage = Language::Befunge::Storage::2D::Sparse->new;
$storage->clear;
$storage->store(<<EOF);
12345
67890
EOF

This class implements a storage as defined in LBS. It makes the assumption that we're in a 2D Funge space for efficiency reasons. Therefore, it's only suited for befunge programs.
This storage is sparse, using a private hash with keys such as "$x,$y". Any value of a non-existing key defaults to 32 (space), as defined by funge specs.

Create a new LBS object.
Clear the storage.
Store the given $code at the specified $position (defaulting to the origin coordinates).
Return the size of the code inserted, as a vector.
The code is a string, representing a block of Funge code. This is binary insertion, that is, EOL sequences are stored in Funge-space instead of causing the dimension counters to be resetted and incremented.
Store the given $code at the specified $position (defaulting to the origin coordinates).
Return the size of the code inserted, as a vector.
The code is a string, representing a block of Funge code. Rows are separated by newlines.
Write the supplied $value in the storage at the specified $offset.
/!\ As in Befunge, code and data share the same playfield, the number stored can be either an instruction or raw data (or even both... Eh, that's Befunge! :o) ).
Return the dimensionality of the storage. For this module, the value is always 2.
Return a LBV pointing to the lower bounds of the storage.
Return a LBV pointing to the upper bounds of the storage.
Return the number stored in the torus at the specified $offset. If the value hasn't yet been set, it defaults to the ordinal value of a space (ie, #32).
/!\ As in Befunge, code and data share the same playfield, the number returned can be either an instruction or raw data (or even both... Eh, that's Befunge! :o) ).
Return the character stored in the torus at the specified $offset. If the value is not between 0 and 255 (inclusive), get_char will return a string that looks like <np-0x4500>.
/!\ As in Befunge, code and data share the same playfield, the character returned can be either an instruction or raw data. No guarantee is made that the return value is printable.
Return a string containing the data/code in the rectangle defined by the supplied vectors.
Parse the storage to find sequences such as ;:(\w[^\s;])[^;]*; and return a hash reference whose keys are the labels and the values an anonymous array with four values: a vector describing the absolute position of the character just after the trailing ;, and a vector describing the velocity that leads to this label.
This method will only look in the four cardinal directions, and does wrap basically like befunge93 (however, this should not be a problem since we're only using cardinal directions)
This allow to define some labels in the source code, to be used by Inline::Befunge (and maybe some exstensions).


Jerome Quelin, <jquelin@cpan.org>

Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.