APR-HTTP-Headers-Compat
view release on metacpan or search on metacpan
lib/APR/HTTP/Headers/Compat/MagicArray.pm view on Meta::CPAN
my ( $self, $key ) = @_;
return $self->{a}[$key];
}
# Sync the table with our state
sub _sync {
my $self = shift;
my ( $table, $fld, @vals )
= ( $self->{m}->table, $self->{f}, @{ $self->{a} } );
$table->set( $fld, shift @vals );
$table->add( $fld, $_ ) for @vals;
}
sub STORE {
my ( $self, $key, $value ) = @_;
$self->{a}[$key] = $value;
$self->_sync;
}
sub FETCHSIZE { scalar @{ shift->{a} } }
lib/APR/HTTP/Headers/Compat/MagicArray.pm view on Meta::CPAN
return $val;
}
sub UNSHIFT {
my ( $self, @list ) = @_;
unshift @{ $self->{a} }, @list;
$self->_sync;
}
sub SPLICE {
my ( $self, $offset, $length, @list ) = @_;
splice @{ $self->{a} }, $offset, $length, @list;
$self->_sync;
}
sub EXISTS {
my ( $self, $key ) = @_;
return $key < @{ $self->{a} };
}
sub EXTEND { }
sub DESTROY { }
lib/APR/HTTP/Headers/Compat/MagicHash.pm view on Meta::CPAN
# return $self->{hash}{$nkey};
}
sub STORE {
my ( $self, $key, $value ) = @_;
my $nkey = $self->_nicefor( $key );
$self->{rmap}{$nkey} = $key;
my $table = $self->table;
my @vals = 'ARRAY' eq ref $value ? @$value : $value;
$table->set( $nkey, shift @vals );
$table->add( $nkey, $_ ) for @vals;
$self->_changed;
}
sub DELETE {
my ( $self, $key ) = @_;
my $nkey = $self->_nicefor( $key );
my $rv = $self->FETCH( $key );
$self->table->unset( $nkey );
$self->_changed;
return $rv;
}
sub CLEAR {
my ( $self ) = @_;
$self->table->clear;
$self->_changed;
}
{
my $table = APR::Table::make( $Pool, 1 );
ok my $h = APR::HTTP::Headers::Compat->new( $table, Foo => 'bar' ),
'new';
is_deeply [ tcont( $table ) ], [ Foo => 'bar' ], 'init';
}
{
my $table = APR::Table::make( $Pool, 1 );
ok my $h = APR::HTTP::Headers::Compat->new( $table ), 'new';
$table->set( Foo => 'bar' );
is $h->header( 'Foo' ), 'bar', 'alter table';
$table->add( Foo => 'baz' );
is_deeply [ $h->header( 'Foo' ) ], [ 'bar', 'baz' ],
'alter table again';
}
sub tcont {
my $table = shift;
my @cont = ();
$table->do(
( run in 1.180 second using v1.01-cache-2.11-cpan-49f99fa48dc )