~ubuntu-branches/ubuntu/edgy/libtext-pdf-perl/edgy

« back to all changes in this revision

Viewing changes to lib/Text/PDF/Array.pm

  • Committer: Bazaar Package Importer
  • Author(s): Gunnar Wolf
  • Date: 2003-06-19 13:37:58 UTC
  • Revision ID: james.westby@ubuntu.com-20030619133758-6qa8nc1qryh9fv33
Tags: upstream-0.25
ImportĀ upstreamĀ versionĀ 0.25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Text::PDF::Array;
 
2
 
 
3
use strict;
 
4
use vars qw(@ISA);
 
5
# no warnings qw(uninitialized);
 
6
 
 
7
use Text::PDF::Objind;
 
8
@ISA = qw(Text::PDF::Objind);
 
9
 
 
10
=head1 NAME
 
11
 
 
12
Text::PDF::Array - Corresponds to a PDF array. Inherits from L<PDF::Objind>
 
13
 
 
14
=head1 INSTANCE VARIABLES
 
15
 
 
16
This object is not an array but an associative array containing the array of
 
17
elements. Thus, there are special instance variables for an array object, beginning
 
18
with a space
 
19
 
 
20
=item var
 
21
 
 
22
Contains the actual array of elements
 
23
 
 
24
=head1 METHODS
 
25
 
 
26
=head2 PDF::Array->new($parent, @vals)
 
27
 
 
28
Creates an array with the given storage parent and an optional list of values to
 
29
initialise the array with.
 
30
 
 
31
=cut
 
32
 
 
33
sub new
 
34
{
 
35
    my ($class, @vals) = @_;
 
36
    my ($self);
 
37
 
 
38
    $self->{' val'} = [@vals];
 
39
    $self->{' realised'} = 1;
 
40
    bless $self, $class;
 
41
}
 
42
 
 
43
 
 
44
=head2 $a->outobjdeep($fh, $pdf)
 
45
 
 
46
Outputs an array as a PDF array to the given filehandle.
 
47
 
 
48
=cut
 
49
 
 
50
sub outobjdeep
 
51
{
 
52
    my ($self, $fh, $pdf, %opts) = @_;
 
53
    my ($obj);
 
54
 
 
55
    $fh->print("[ ");
 
56
    foreach $obj (@{$self->{' val'}})
 
57
    {
 
58
        $obj->outobj($fh, $pdf, %opts);
 
59
        $fh->print(" ");
 
60
    }
 
61
    $fh->print("]");
 
62
}
 
63
 
 
64
 
 
65
=head2 $a->removeobj($elem)
 
66
 
 
67
Removes all occurrences of an element from an array.
 
68
 
 
69
=cut
 
70
 
 
71
sub removeobj
 
72
{
 
73
    my ($self, $elem) = @_;
 
74
 
 
75
    $self->{' val'} = [grep($_ ne $elem, @{$self->{' val'}})];
 
76
}   
 
77
 
 
78
 
 
79
=head2 $a->elementsof
 
80
 
 
81
Returns a list of all the elements in the array. Notice that this is
 
82
not the array itself but the elements in the array.
 
83
 
 
84
=cut
 
85
 
 
86
sub elementsof
 
87
{ wantarray ? @{$_[0]->{' val'}} : scalar @{$_[0]->{' val'}}; }
 
88
 
 
89
 
 
90
=head2 $a->add_elements
 
91
 
 
92
Appends the given elements to the array. An element is only added if it
 
93
is defined.
 
94
 
 
95
=cut
 
96
 
 
97
sub add_elements
 
98
{
 
99
    my ($self) = shift;
 
100
    my ($e);
 
101
 
 
102
    foreach $e (@_)
 
103
    { push (@{$self->{' val'}}, $e) if defined $e; }
 
104
    $self;
 
105
}
 
106
 
 
107
 
 
108
=head2 $a->val
 
109
 
 
110
Returns the value of the array, this is a reference to the actual array
 
111
containing the elements.
 
112
 
 
113
=cut
 
114
 
 
115
sub val
 
116
{ $_[0]->{' val'}; }
 
117
 
 
118
 
 
119
=head2 $d->copy($inpdf, $res, $unique, $outpdf, %opts)
 
120
 
 
121
Copies an object. See Text::PDF::Objind::Copy() for details
 
122
 
 
123
=cut
 
124
 
 
125
sub copy
 
126
{
 
127
    my ($self, $inpdf, $res, $unique, $outpdf, %opts) = @_;
 
128
    my ($i, $path);
 
129
 
 
130
    $res = $self->SUPER::copy($inpdf, $res, $unique, $outpdf, %opts);
 
131
    $res->{' val'} = [];
 
132
    $path = delete $opts{'path'};
 
133
    for ($i = 0; $i < scalar @{$self->{' val'}}; $i++)
 
134
    {
 
135
        if (UNIVERSAL::can($self->{'val'}[$i], "is_obj") && !grep {"$path\[$i\]" =~ m|$_|} @{$opts{'clip'}})
 
136
        { push (@{$res->{' val'}}, $self->{' val'}[$i]->realise->copy($inpdf, undef, $unique ? $unique + 1 : 0,
 
137
                        $outpdf, %opts, 'path' => "$path\[$i\]")); }
 
138
        else
 
139
        { push (@{$res->{' val'}}, $self->{' val'}[$i]); }
 
140
    }
 
141
    $res->{' realised'} = 1;
 
142
    $res;
 
143
}
 
144
 
 
145
1;
 
146
 
 
147