Text::Bidi::Array(3) Base class for dual life arrays


version 2.11


use Text::Bidi::Array::Byte;
my $a = new Text::Bidi::Array::Byte "abc";
say $a->[1]; # says 98
say $$a; # says abc
say "$a"; # also says abc


This is an abstract base class for objects that function as ``dual-life'' arrays: When viewed as an array reference, it functions as a usual array of numbers. When used as a scalar reference, it returns the same array as a packed string. The packing specification depends on the sub-class. These classes are used in Text::Bidi to conveniently pass arrays to the underlying fribidi library, but could be of independent interest.


An object of this type can be dereferenced either as a scalar or as an array. In the first case, it returns the packed (string) representation of the array. In the second, it returns the unpacked array of numbers.

The packed representation is also returned when the object is used as a string.


    $a = new Text::Bidi::Array::<Type> $data

Create a new array of the given Type, and initialise it with $data. $data can be either a string, which the new object then view as an array of the given type, or an array reference (more precisely, anything that can be dereferenced as an array), which is then packed according to the rules of Type. If no $data is given, it defaults to 0.


The rest of this documentation is for writing specific derived classes. The object is represented internally as a hashref. To implement a particular instance, the following methods should be implemented. Each of these should manipulate the field "data", which is the string that stores the actual value. Unimplemented methods will lead to croaking. See Text::Bidi::Array::Byte and Text::Bidi::Array::Long for examples.
Convert (pack) an array of numbers into a string according to the format of the current class (this will probably be a class method). Returns the string.

The following methods should behave as described in Tie::Array.

$self->STORE($index, $value)
Store the $value in the part of "$self->{'data'}" corresponding to $index.
Fetch the value at $index from the correct part of "$self->{'data'}".
Modify "$self->{'data'}" to represent an array of size $count.
Return the size of the array represented by "$self->{'data'}".


Moshe Kamensky <[email protected]>


This software is copyright (c) 2015 by Moshe Kamensky.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.