Text::PDF::Array - Corresponds to a PDF array. Inherits from L<PDF::Objind>


Text-PDF documentation Contained in the Text-PDF distribution.

Index


Code Index:

NAME

Top

Text::PDF::Array - Corresponds to a PDF array. Inherits from PDF::Objind

INSTANCE VARIABLES

Top

This object is not an array but an associative array containing the array of elements. Thus, there are special instance variables for an array object, beginning with a space

Contains the actual array of elements

METHODS

Top

PDF::Array->new($parent, @vals)

Creates an array with the given storage parent and an optional list of values to initialise the array with.

$a->outobjdeep($fh, $pdf)

Outputs an array as a PDF array to the given filehandle.

$a->removeobj($elem)

Removes all occurrences of an element from an array.

$a->elementsof

Returns a list of all the elements in the array. Notice that this is not the array itself but the elements in the array.

$a->add_elements

Appends the given elements to the array. An element is only added if it is defined.

$a->val

Returns the value of the array, this is a reference to the actual array containing the elements.

$d->copy($inpdf, $res, $unique, $outpdf, %opts)

Copies an object. See Text::PDF::Objind::Copy() for details


Text-PDF documentation Contained in the Text-PDF distribution.
package Text::PDF::Array;

use strict;
use vars qw(@ISA);
# no warnings qw(uninitialized);

use Text::PDF::Objind;
@ISA = qw(Text::PDF::Objind);

sub new
{
    my ($class, @vals) = @_;
    my ($self);

    $self->{' val'} = [@vals];
    $self->{' realised'} = 1;
    bless $self, $class;
}


sub outobjdeep
{
    my ($self, $fh, $pdf, %opts) = @_;
    my ($obj);

    $fh->print("[ ");
    foreach $obj (@{$self->{' val'}})
    {
        $obj->outobj($fh, $pdf, %opts);
        $fh->print(" ");
    }
    $fh->print("]");
}


sub removeobj
{
    my ($self, $elem) = @_;

    $self->{' val'} = [grep($_ ne $elem, @{$self->{' val'}})];
}   


sub elementsof
{ wantarray ? @{$_[0]->{' val'}} : scalar @{$_[0]->{' val'}}; }


sub add_elements
{
    my ($self) = shift;
    my ($e);

    foreach $e (@_)
    { push (@{$self->{' val'}}, $e) if defined $e; }
    $self;
}


sub val
{ $_[0]->{' val'}; }


sub copy
{
    my ($self, $inpdf, $res, $unique, $outpdf, %opts) = @_;
    my ($i, $path);

    $res = $self->SUPER::copy($inpdf, $res, $unique, $outpdf, %opts);
    $res->{' val'} = [];
    $path = delete $opts{'path'};
    for ($i = 0; $i < scalar @{$self->{' val'}}; $i++)
    {
        if (UNIVERSAL::can($self->{'val'}[$i], "is_obj") && !grep {"$path\[$i\]" =~ m|$_|} @{$opts{'clip'}})
        { push (@{$res->{' val'}}, $self->{' val'}[$i]->realise->copy($inpdf, undef, $unique ? $unique + 1 : 0,
                        $outpdf, %opts, 'path' => "$path\[$i\]")); }
        else
        { push (@{$res->{' val'}}, $self->{' val'}[$i]); }
    }
    $res->{' realised'} = 1;
    $res;
}

1;