Thank you for the info Adam. I already wrote a wrapper that does just that. I was hoping to find an alternative but and I guess I will stick with the wrapper.
Jimmy On Nov 26, 2007 8:37 AM, <[EMAIL PROTECTED]> wrote: > Quoting Jimmy Li <[EMAIL PROTECTED]>: > > > > How did you put all the request parameters into an APR::Table object? > > Did you figure out an easy way to do it? > > > > Jimmy > > > > Looking at the APR::Request::Param::Table API (near the bottom of this > page: > http://httpd.apache.org/apreq/docs/libapreq2/group__apreq__xs__apr__request.html > the anchors don't work), the easiest way to do it would be to use > do(). > > something like this (untested, ymmv) > > my @params = $r->param(); > my $new_table = APR::Table::make($r->pool, scalar @params); > $r->param()->do( > sub { > my ($k,$v) = @_; > $new_table->add($k => $v); > return 1; > } > ); > > That creates a closure around $new_table though (unless i'm mistaken) > which isn't a good thing. Someone with a better understanding of this > than me would probably do a better job explaining it, and whether it > applies here. > > Alternatively you could just loop through the parameters and stuff > them into your table. You just have to be careful because with > libapreq2 > > my @keys = $r->param(); > > does not return only distinct keys. If 'foo' has 2 values, it'll > appear in @keys twice. (Another difference from libapreq1, and this > one I think actually is undocumented). you can work around that with > this: > > my $params = $r->param(); > my %table_keys = %$params if $params; > my @distinct_keys = keys (%table_keys); > > Realistically though, neither of these options are the greatest > because they wholesale copy all the parameters your client decides to > send in whether you want them or not. It might be better to build > some sort of wrapper that would copy things over into your new table > when you use the parameter the first time, and if it's already copied > just uses your new one. This would eliminate a minor possibility for > abuse. > > Adam > > >