NAME

PDF::Make::Obj - PDF object wrapper

SYNOPSIS

use PDF::Make::Arena;
use PDF::Make::Obj qw(:kinds);

my $arena = PDF::Make::Arena->new;

# Create objects
my $int = $arena->int(42);
my $str = $arena->str('Hello');

# Type checking
print $int->kind;       # 2 (KIND_INT)
print $int->is_int;     # 1
print $int->is_str;     # 0

# Get value
print $int->value;      # 42
print $str->value;      # Hello

# Array operations
my $arr = $arena->array;
$arr->push($int)->push($str);
print $arr->len;        # 2
my $first = $arr->get(0);

# Dict operations
my $dict = $arena->dict;
$dict->set('Type', $arena->name('Catalog'));
$dict->set('Count', $arena->int(1));
print $dict->len;       # 2
print $dict->has('Type'); # 1
my $type = $dict->get('Type');

DESCRIPTION

PDF::Make::Obj wraps PDF objects created via PDF::Make::Arena. Objects are arena-allocated and automatically freed when the arena is destroyed.

METHODS

kind

my $k = $obj->kind;

Return the object kind (see KIND_* constants).

Type Predicates

$obj->is_null
$obj->is_bool
$obj->is_int
$obj->is_real
$obj->is_numeric   # int or real
$obj->is_name
$obj->is_str
$obj->is_array
$obj->is_dict
$obj->is_stream
$obj->is_ref

Return true if the object is of the specified type.

value

my $val = $obj->value;

Return the scalar value for primitive types (null, bool, int, real, name, str). Returns undef for composite types.

Array Methods

push

$arr->push($obj);

Append an object to the array. Returns $self for chaining.

len

my $n = $arr->len;

Return the number of elements in the array.

get

my $elem = $arr->get($index);

Return the element at the given index (0-based).

Dict Methods

set

$dict->set($key, $obj);

Set a dictionary entry. $key is a string (will be interned as a name). Returns $self for chaining.

get

my $val = $dict->get($key);

Get the value for a key. Returns undef if not found.

has

my $exists = $dict->has($key);

Return true if the key exists in the dictionary.

del

$dict->del($key);

Delete a key from the dictionary.

len

my $n = $dict->len;

Return the number of entries in the dictionary.

Ref Methods

ref_num

my $num = $ref->ref_num;

Return the object number of an indirect reference.

ref_gen

my $gen = $ref->ref_gen;

Return the generation number of an indirect reference.

CONSTANTS

:kinds

use PDF::Make::Obj qw(:kinds);
  • KIND_NULL (0)

  • KIND_BOOL (1)

  • KIND_INT (2)

  • KIND_REAL (3)

  • KIND_NAME (4)

  • KIND_STR (5)

  • KIND_ARRAY (6)

  • KIND_DICT (7)

  • KIND_STREAM (8)

  • KIND_REF (9)

SEE ALSO

PDF::Make::Arena, PDF::Make::Document