mod_perl logo
perl icon







previous page: APR:PerlIO -- An APR Perl IO layerpage up: mod_perl APIsnext page: ModPerl::MethodLookup -- Map mod_perl 2.0 modules, objects and methods


APR::Table -- A Perl API for manipulating opaque string-content table











Practical mod_perl

Practical mod_perl

By Stas Bekman, Eric Cholet
The mod_perl Developer's Cookbook

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Kobes
mod_perl Pocket Reference

mod_perl Pocket Reference

By Andrew Ford


Table of Contents

SYNOPSIS

  use APR::Table;
  
  $table = make($pool, $nelts);
  $table_copy = $table->copy($pool);
  
  $table->clear();
  
  $table->set($key => $val);
  $table->unset($key);
  $table->add($key, $val);
  
  $val = $table->get($key);
  @val = $table->get($key);
  
  $table->merge($key => $val);
  overlap($table_a, $table_b, $flags);
  $new_table = overlay($table_base, $table_overlay, $pool);
  
  $table->do(sub {print "key $_[0], value $_[1]\n"}, @valid_keys);
  
  #Tied Interface
  $value = $table->{$key};
  $table->{$key} = $value;
  $table->{$key} = $value;
  exists $table->{$key};
  
  foreach my $key (keys %{$table}) {
      print "$key = $table->{$key}\n";
  }


TOP

DESCRIPTION

APR::Table allows its users to manipulate opaque string-content tables.

The table's structure is somewhat similar to the Perl's hash structure, but allows multiple values for the same key. An access to the records stored in the table always requires a key.

The key-value pairs are stored in the order they are added.

The keys are case-insensitive.

However as of the current implementation if more than value for the same key is requested, the whole table is lineary searched, which is very inefficient unless the table is very small.

APR::Table provides a TIE Interface.

See apr/include/apr_tables.h in ASF's apr project for low level details.



TOP

API

The variables used in the API definition have the following "types":

Function arguments (if any) and return values are shown in the function's synopsis.



TOP

TIE Interface

APR::Table also implements a tied interface, so you can work with the $table object as a hash reference.

The following tied-hash function are supported: FETCH, STORE, DELETE, CLEAR, EXISTS, FIRSTKEY, NEXTKEY and DESTROY.

remark: APR::Table can hold more than one key-value pair sharing the same key, so when using a table through the tied interface, the first entry found with the right key will be used, completely disregarding possible other entries with the same key. The only exception to this is if you iterate over the list with each, then you can access all key-value pairs that share the same key.







TOP
previous page: APR:PerlIO -- An APR Perl IO layerpage up: mod_perl APIsnext page: ModPerl::MethodLookup -- Map mod_perl 2.0 modules, objects and methods