Text::Bidi::Array(3pm) | User Contributed Perl Documentation | Text::Bidi::Array(3pm) |
Text::Bidi::Array - Base class for dual life arrays
version 2.15
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.
Text::Bidi::Array::Byte, Text::Bidi::Array::Long
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.
The following methods should behave as described in Tie::Array.
Moshe Kamensky <kamensky@cpan.org>
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.
2022-10-19 | perl v5.36.0 |