stas 01/09/28 10:20:32
Modified: t/response/TestAPR table.pm
xs/APR/Table APR__Table.h
xs/maps apr_functions.map
Log:
- the list context APR::Table::get implementation + tests
Revision Changes Path
1.4 +18 -7 modperl-2.0/t/response/TestAPR/table.pm
Index: table.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/table.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- table.pm 2001/09/25 19:44:03 1.3
+++ table.pm 2001/09/28 17:20:32 1.4
@@ -14,7 +14,7 @@
sub handler {
my $r = shift;
- plan $r, tests => 16;
+ plan $r, tests => 17;
my $table = APR::Table::make($r->pool, $TABLE_SIZE);
@@ -22,8 +22,18 @@
ok $table->set('foo','bar') || 1;
+ # scalar context
ok $table->get('foo') eq 'bar';
+ # add + list context
+ $table->add(foo => 'tar');
+ $table->add(foo => 'kar');
+ my @array = $table->get('foo');
+ ok @array == 3 &&
+ $array[0] eq 'bar' &&
+ $array[1] eq 'tar' &&
+ $array[2] eq 'kar';
+
ok $table->unset('foo') || 1;
ok not defined $table->get('foo');
@@ -62,13 +72,14 @@
#Tied interface
{
my $table = APR::Table::make($r->pool, $TABLE_SIZE);
-
+
ok (UNIVERSAL::isa($table, 'HASH'));
-
+
ok (UNIVERSAL::isa($table, 'HASH')) && tied(%$table);
-
+
ok $table->{'foo'} = 'bar';
+ # scalar context
ok $table->{'foo'} eq 'bar';
ok delete $table->{'foo'} || 1;
@@ -76,16 +87,16 @@
ok not exists $table->{'foo'};
for (1..$TABLE_SIZE) {
- $table->{chr($_+97)} = $_ ;
+ $table->{chr($_+97)} = $_;
}
$filter_count = 0;
foreach my $key (sort keys %$table) {
- my_filter($key,$table->{$key});
+ my_filter($key, $table->{$key});
}
ok $filter_count == $TABLE_SIZE;
}
-
+
Apache::OK;
}
1.5 +39 -0 modperl-2.0/xs/APR/Table/APR__Table.h
Index: APR__Table.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/Table/APR__Table.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- APR__Table.h 2001/09/25 19:44:03 1.4
+++ APR__Table.h 2001/09/28 17:20:32 1.5
@@ -126,3 +126,42 @@
return mpxs_APR__Table_NEXTKEY(tsv, Nullsv);
}
+
+static XS(MPXS_apr_table_get)
+{
+ dXSARGS;
+
+ if (items != 2) {
+ Perl_croak(aTHX_ "Usage: $table->get($key)");
+ }
+
+ mpxs_PPCODE({
+ APR__Table t = modperl_hash_tied_object(aTHX_ "APR::Table", ST(0));
+ const char *key = (const char *)SvPV_nolen(ST(1));
+
+ if (!t) {
+ XSRETURN_UNDEF;
+ }
+
+ if(GIMME_V == G_SCALAR) {
+ const char *val = apr_table_get(t, key);
+
+ if (val) {
+ XPUSHs(sv_2mortal(newSVpv((char*)val, 0)));
+ }
+ }
+ else {
+ apr_array_header_t *arr = apr_table_elts(t);
+ apr_table_entry_t *elts = (apr_table_entry_t *)arr->elts;
+ int i;
+
+ for (i = 0; i < arr->nelts; i++) {
+ if (!elts[i].key || strcasecmp(elts[i].key, key)) {
+ continue;
+ }
+ XPUSHs(sv_2mortal(newSVpv(elts[i].val,0)));
+ }
+ }
+ });
+
+}
1.23 +1 -1 modperl-2.0/xs/maps/apr_functions.map
Index: apr_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/apr_functions.map,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apr_functions.map 2001/09/25 19:44:03 1.22
+++ apr_functions.map 2001/09/28 17:20:32 1.23
@@ -184,7 +184,7 @@
apr_table_add
-apr_table_addn
apr_table_do | mpxs_ | ...
- apr_table_get
+ apr_table_get | MPXS_ | ...
apr_table_merge
-apr_table_mergen
apr_table_set