Return-Path: Delivered-To: apmail-perl-dev-archive@perl.apache.org Received: (qmail 84612 invoked by uid 500); 29 Nov 2001 10:50:07 -0000 Mailing-List: contact dev-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@perl.apache.org Received: (qmail 84601 invoked from network); 29 Nov 2001 10:50:06 -0000 Date: Thu, 29 Nov 2001 18:50:15 +0800 From: "Philippe M. Chiasson" To: dev@perl.apache.org Subject: [patch] $table->as_string() and "$table" Message-ID: <20011129185015.A27606@eXtropia.com> Reply-To: "Philippe M. Chiasson" Mail-Followup-To: dev@perl.apache.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="huq684BweRXVnRxX" Content-Disposition: inline User-Agent: Mutt/1.3.18i X-Virus-Scanned: AMaViS X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Following patch includes $r->as_string() and "$string" to dump a table in a format like: key=3D'value'\n keyn=3D'valuen'\n Also renamed mpxs_table_do_cb_data_t.cv to mpxs_table_do_cb_data_t.sv for clarity, as I needed it again for the as_string() implementation to store a simple SV* Also, wish it could be easier to use 'overload' from C/XS /home/gozer/sources/mod_perl2/deps/perl-13279/bin/perl build/cvsdiff=20 Index: xs/APR/Table/APR__Table.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/anoncvs/mod_perl-2-cvs/xs/APR/Table/APR__Table.h,v retrieving revision 1.7 diff -u -I'$Id' -I'$Revision' -r1.7 APR__Table.h --- xs/APR/Table/APR__Table.h 12 Nov 2001 22:14:36 -0000 1.7 +++ xs/APR/Table/APR__Table.h 29 Nov 2001 10:21:53 -0000 @@ -4,7 +4,7 @@ #define mpxs_APR__Table_CLEAR apr_table_clear =20 typedef struct { - SV *cv; + SV *sv; apr_hash_t *filter; PerlInterpreter *perl; } mpxs_table_do_cb_data_t; @@ -20,7 +20,7 @@ int rv =3D 0; =20 /* Skip completely if something is wrong */ - if (!(tdata && tdata->cv && key && val)) { + if (!(tdata && tdata->sv && key && val)) { return 0; } =20 @@ -39,7 +39,7 @@ XPUSHs(sv_2mortal(newSVpv(val,0))); PUTBACK; =20 - rv =3D call_sv(tdata->cv, 0); + rv =3D call_sv(tdata->sv, 0); SPAGAIN; rv =3D (1 =3D=3D rv) ? POPi : 1; PUTBACK; @@ -60,7 +60,7 @@ =20 mpxs_usage_va_2(table, sub, "$table->do(sub, [@filter])"); =20 - tdata.cv =3D sub; + tdata.sv =3D sub; tdata.filter =3D NULL; #ifdef USE_ITHREADS tdata.perl =3D aTHX; @@ -163,4 +163,28 @@ } }); =20 +} + +static int sv_str_header(void *data, const char *k, const char *v) +{ + mpxs_table_do_cb_data_t *tdata =3D (mpxs_table_do_cb_data_t *)data; + dTHXa(tdata->perl); + sv_catpvf(tdata->sv, "%s=3D'%s'\n", k, v); + return 1; +} + +static MP_INLINE +SV *mpxs_APR__Table_as_string(pTHX_ SV *tsv) +{ + SV *string =3D newSVpv("", 0); + mpxs_table_do_cb_data_t tdata; + +#ifdef USE_ITHREADS + tdata.perl =3D aTHX; +#endif + tdata.sv =3D string; + =20 + apr_table_t *t =3D mp_xs_sv2_APR__Table(tsv); + apr_table_do(&sv_str_header, &tdata, t, NULL); + return string; } Index: t/response/TestAPR/table.pm =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPR/table.pm,v retrieving revision 1.4 diff -u -I'$Id' -I'$Revision' -r1.4 table.pm --- t/response/TestAPR/table.pm 28 Sep 2001 17:20:32 -0000 1.4 +++ t/response/TestAPR/table.pm 29 Nov 2001 10:21:54 -0000 @@ -14,7 +14,7 @@ sub handler { my $r =3D shift; =20 - plan $r, tests =3D> 17; + plan $r, tests =3D> 19; =20 my $table =3D APR::Table::make($r->pool, $TABLE_SIZE); =20 @@ -24,6 +24,9 @@ =20 # scalar context ok $table->get('foo') eq 'bar'; + =20 + ok $table->as_string() eq "foo=3D'bar'\n"; + ok "$table" eq "foo=3D'bar'\n"; =20 # add + list context $table->add(foo =3D> 'tar'); Index: docs/src/api/mod_perl-2.0/APR/Table.pod =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/anoncvs/mod_perl-docs-cvs/src/api/mod_perl-2.0/APR/Table.po= d,v retrieving revision 1.2 diff -u -I'$Id' -I'$Revision' -r1.2 Table.pod --- docs/src/api/mod_perl-2.0/APR/Table.pod 22 Oct 2001 15:47:17 -0000 1.2 +++ docs/src/api/mod_perl-2.0/APR/Table.pod 29 Nov 2001 10:21:54 -0000 @@ -22,6 +22,10 @@ overlap($table_a, $table_b, $flags); $new_table =3D overlay($table_base, $table_overlay, $pool); =20 + #Dumping a table + print STDERR "Table looks like:\n" . $table->as_string(); + print STDERR "Table looks like:$table"; + =20 #Tied Interface $value =3D $table->{$key}; $table->{$key} =3D $value; @@ -230,6 +234,21 @@ param C<$table_base>: The table to add at the end of the new table =20 return: A new table containing all of the data from the two passed in + +=3Ditem * as_string() + + print STDERR $table->as_string(); + +Returns a string representation of the table, usefull for debugging +purposes. + +=3Ditem * "$table" + + print STDERR "Table is : $table"; + =20 +Used in string context, a table will output a string representation=20 +of the table, usefull for debugging purposes. +=20 =20 =3Dback =20 --- /dev/null Fri Aug 31 04:30:55 2001 +++ xs/APR/Table/Table_pm Thu Nov 29 18:04:01 2001 @@ -0,0 +1,5 @@ +use overload q("") =3D> \&stringify; + +sub stringify { + return shift->as_string(); +} Index: xs/maps/apr_functions.map =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apr_functions.map,v retrieving revision 1.25 diff -u -I'$Id' -I'$Revision' -r1.25 apr_functions.map --- xs/maps/apr_functions.map 22 Oct 2001 01:52:06 -0000 1.25 +++ xs/maps/apr_functions.map 29 Nov 2001 10:21:54 -0000 @@ -198,6 +198,7 @@ mpxs_APR__Table_FIRSTKEY mpxs_APR__Table_NEXTKEY mpxs_APR__Table_EXISTS + mpxs_APR__Table_as_string =20 !MODULE=3DAPR::File -apr_file_open --=20 Philippe M. Chiasson Extropia's Resident System Guru http://www.eXtropia.com/ /* When we have more time, we can teach the penguin to say=20 * "By your command" or "Activating turbo boost, Michael". */=20 -- Linux 2.2.16 /usr/src/linux/arch/sparc/prom/sun4prom.c perl -e '$$=3D\${gozer};{$_=3Dunpack(P26,pack(L,$$));/^Just Another Perl Ha= cker!\n$/&&print||$$++&&redo}' --huq684BweRXVnRxX Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8BhLmyzKhB4jDpaURAowGAKC7PU3nCx14SxxFW7B3Nu634b4/JgCfbeph qrvXWvtzY742aDd4VkSu408= =660o -----END PGP SIGNATURE----- --huq684BweRXVnRxX--