Joe Schaefer wrote:
Stas Bekman <[EMAIL PROTECTED]> writes:


Joe Schaefer wrote:

Stas Bekman <[EMAIL PROTECTED]> writes:


Hmm, what about storing the pointer to apreq_value_t as val

AFAICT, that helps nada.

true, again because of newSVpv



in the table and subclass get() to do what you want?

Just subclassing get() might work! At the moment I'm concerned about how each() is implemented; does each make a call to FETCH to get at the value? If so, how does it handle multivalued keys?

From the perltie manpage:


  FIRSTKEY and NEXTKEY implement the keys() and each() functions
  to iterate over all the keys.


Unfortunately that's a borked approach when multivalued keys are present: values() and each() (in list context)
will always grab the first value instead of the "current" one. The remark at the bottom of docs/api/APR/Table.pod
appears to be incorrect:


  ... The only exception to this is if you iterate over the list with
  I<each>, then you can access all key-value pairs that share the same key.

See test below (tests 8 & 10 check the above assertion, and fail for me).


looks like mpxs_APR__Table_NEXTKEY is correct, though we don't really
have a test in t/response/TestAPR/table.pm for this.


It looks ok to me also- too bad the TIEHASH api doesn't have
EACH & VALUES subs.

Index: t/response/TestAPR/table.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/response/TestAPR/table.pm,v
retrieving revision 1.5
diff -u -r1.5 table.pm
--- t/response/TestAPR/table.pm 11 Apr 2002 11:08:44 -0000      1.5
+++ t/response/TestAPR/table.pm 5 Jun 2003 06:57:28 -0000
@@ -15,7 +15,7 @@
 sub handler {
     my $r = shift;

-    plan $r, tests => 17;
+    plan $r, tests => 23;

my $table = APR::Table::make($r->pool, $TABLE_SIZE);

@@ -34,6 +34,12 @@
        $array[0] eq 'bar' &&
        $array[1] eq 'tar' &&
        $array[2] eq 'kar';
+
+    for (0..2) {
+        ($a, $b) = each %$table;
+        ok $a eq 'foo';
+        ok $b eq $array[$_];
+    }

ok $table->unset('foo') || 1;


correct it's not working.


so we can't simply alias FETCH to apr_table_get, the following sort of works (but breaks some other things):

static MP_INLINE
const char *mpxs_APR__Table_FETCH(pTHX_ SV *tsv, const char *key)
{
    apr_table_t *t = mp_xs_sv2_APR__Table(tsv);

    if (!t) {
        return "";
    }

    if (!mpxs_apr_table_iterix(tsv)) {
        return apr_table_get(t, key);
    }
    else {
        const apr_array_header_t *arr = apr_table_elts(t);
        apr_table_entry_t *elts  = (apr_table_entry_t *)arr->elts;
        return elts[mpxs_apr_table_iterix(tsv)-1].val;
    }
}

I'm not sure if it's a good idea though.


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to