Apache-FakeTable
view release on metacpan or search on metacpan
lib/Apache/FakeTable.pm view on Meta::CPAN
package Apache::FakeTable;
use strict;
use vars qw($VERSION);
$VERSION = '0.06';
=head1 Name
Apache::FakeTable - Pure Perl implementation of the Apache::Table interface
=head1 Synopsis
use Apache::FakeTable;
my $table = Apache::FakeTable->new($r);
$table->set(From => 'david@example.com');
$table->add(Cookie => 'One Cookie');
$table->add(Cookie => 'Another Cookie');
while(my($key, $val) = each %$table) {
print "$key: $val\n";
}
=head1 Description
This class emulates the behavior of the L<Apache::Table> class, and is
designed to behave exactly like Apache::Table. This means that all keys are
case-insensitive and may have multiple values. As a drop-in substitute for
Apache::Table, you should be able to use it exactly like Apache::Table.
You can treat an Apache::FakeTable object much like any other hash. However,
like Apache Table, those keys that contain multiple values will trigger
slightly different behavior than a traditional hash. The variations in
behavior are as follows:
=over
=item keys
Will return the same key multiple times, once for each value stored for that
key.
=item values
Will return the first value multiple times, once for each value stored for a
given key. It'd be nice if it returned all the values for a given key, instead
of the first value C<*> the number of values, but that's not the way
Apache::Table works, and I'm not sure I'd know how to implement it even if it
did!
=item each
Will return the same key multiple times, pairing it with each of its values
in turn.
=back
Otherwise, things should be quite hash-like, particularly when a key has only
a single value.
=head1 Interface
=head3 new()
my $table = Apache::FakeTable->new($r);
$table = Apache::FakeTable->new($r, $initial_size);
Returns a new C<Apache::FakeTable> object. An L<Apache> object is required as
the first argument. An optional second argument sets the initial size of the
table for storing values.
=cut
sub new {
# We actually ignore the optional initial size argument.
my ($class, $r) = @_;
unless (UNIVERSAL::isa($r, 'Apache')) {
require Carp;
( run in 1.388 second using v1.01-cache-2.11-cpan-d06a3f9ecfd )