logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Text::Bidi::Array - Base class for dual life arrays

Author

       Moshe Kamensky <kamensky@cpan.org>

Construction

           $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.

Description

       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.

For Implementors

       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.

       $self->pack(@data)
           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.

       $self->FETCH($index)
           Fetch the value at $index from the correct part of "$self->{'data'}".

       $self->STORESIZE($count)
           Modify "$self->{'data'}" to represent an array of size $count.

       $self->FETCHSIZE()
           Return the size of the array represented by "$self->{'data'}".

Name

       Text::Bidi::Array - Base class for dual life arrays

Overloaded Operators

       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.

See Also

       Text::Bidi::Array::Byte, Text::Bidi::Array::Long

Synopsis

           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

Version

       version 2.18

See Also