You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@cpan.org> on 2003/05/22 10:35:24 UTC

[mp1 Patch] $r->print() handling of $\

For the original report, see:
http://marc.theaimsgroup.com/?l=apache-modperl&m=102874705105904&w=2

Basically, perlvar says that $\ (awk-ish) gets appended to the end of
each call to print().

Following patch attempts to implement this:

$/ is either

char *PL_ors and STRLEN PL_orslen (Perl < 5.8)
or
SV *PL_ors_sv (Perl >5.8)

So that's what those #ifdef are for.

All tests pass OK for me with this.


? t/conf/dev-null
Index: Changes
===================================================================
RCS file: /home/cvs/modperl/Changes,v
retrieving revision 1.666
diff -u -I$Id -r1.666 Changes
--- Changes	7 Apr 2003 23:16:23 -0000	1.666
+++ Changes	22 May 2003 08:34:52 -0000
@@ -10,6 +10,9 @@
 
 =item 1.27_01-dev
 
+$r->print() now honors $\, the output record separator 
+[Philippe M. Chiasson <go...@cpan.org>]
+
 Tweak mod_perl.h to defined _INCLUDE_APACHE_FIRST only after apache
 headers were included [Stas Bekman]
 
Index: STATUS
===================================================================
RCS file: /home/cvs/modperl/STATUS,v
retrieving revision 1.21
diff -u -I$Id -r1.21 STATUS
--- STATUS	7 Aug 2002 19:39:00 -0000	1.21
+++ STATUS	22 May 2003 08:34:52 -0000
@@ -21,13 +21,6 @@
 
 Needs Patch or Further Investigation
 
-    * $r->print() ignores $\
-        Report: http://marc.theaimsgroup.com/?l=apache-modperl&m=102874705105904&w=2
-        Status:
-          not sure what to do with this, just sv_catpvn(sv, $\, 1) in Apache.xs's print()?
-          does that handle everything? (assuming I can figure out how to dig out 
-          what's in $\)  is this really important? --Geoff
-
     * make test fails when a wrong combination of URI and LWP are
       installed. (e.g. lwp 5.64 and URI 1.09). LWP's Makefile.PL
       requires the right URI version, but certain binary distributors
Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.127
diff -u -I$Id -r1.127 Apache.xs
--- src/modules/perl/Apache.xs	14 Mar 2003 06:05:06 -0000	1.127
+++ src/modules/perl/Apache.xs	22 May 2003 08:34:52 -0000
@@ -1137,6 +1137,15 @@
 	CV *cv = GvCV(gv_fetchpv("Apache::write_client", FALSE, SVt_PVCV));
 	soft_timeout("mod_perl: Apache->print", r);
 	PUSHMARK(mark);
+#ifdef PL_ors_sv
+    if(PL_ors_sv && SvOK(PL_ors_sv))
+        XPUSHs(PL_ors_sv);
+#endif
+#ifdef PL_orslen
+    if(PL_orslen)
+        XPUSHp(PL_ors, PL_orslen);
+#endif
+    PUTBACK;
 #ifdef PERL_OBJECT
 	(void)(*CvXSUB(cv))(cv, pPerl); /* &Apache::write_client; */
 #else
Index: t/internal/ors.t
===================================================================
RCS file: t/internal/ors.t
diff -N t/internal/ors.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/internal/ors.t	22 May 2003 08:34:52 -0000
@@ -0,0 +1,9 @@
+use Apache::test;
+
+my $sent = fetch "/perl/ors.pl";
+my $i = 0;
+
+print "1..1\n";
+
+my $string = "ABC\nD\nE_ORS_F_ORS_G";
+test ++$i, $sent eq $string;
Index: t/net/perl/ors.pl
===================================================================
RCS file: t/net/perl/ors.pl
diff -N t/net/perl/ors.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/net/perl/ors.pl	22 May 2003 08:34:52 -0000
@@ -0,0 +1,22 @@
+#!perl
+my $r = Apache->request;
+$r->content_type("text/plain");
+$r->send_http_header;
+
+$r->print('A');
+$r->print('B');
+{
+	local $\ = "\n";
+	$r->print('C');
+	$r->print('D');
+}
+
+{
+	local $\ = "_ORS_";
+	$r->print('E');
+	$r->print('F');
+}
+
+$r->print('G');
+
+



-- 
-- -----------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Re: [mp1 Patch] $r->print() handling of $\

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Thu, 2003-05-22 at 21:11, Geoffrey Young wrote:
> Philippe M. Chiasson wrote:
> > For the original report, see:
> > http://marc.theaimsgroup.com/?l=apache-modperl&m=102874705105904&w=2
> > 
> 
> cool.  you might want to check these out too

Thanks! I didn't see those 2.

> 
> http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=102891528030133&w=2

I definitely prefer my patch to that one to implement $\

> http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=102902480103484&w=2

This patches also discusses support $, proprely, and I think it's also a
valid idea, especially if we are going to fix $\ anyways.

I'll add it to the STATUS and work it in my own patch as well as write a
test for it. Unless somebody thinks of a good reason _not_ to support $,
as well.

For those who might not know it, $, is the output field separator, and
$\ is the output record separator, as show in:

$> perl -le '$,="-";$\="EOR\n";print qw(a b c d)'
a-b-c-dEOR

Gozer out.

> --Geoff
-- 
-- -----------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Re: [mp1 Patch] $r->print() handling of $\

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Philippe M. Chiasson wrote:
> For the original report, see:
> http://marc.theaimsgroup.com/?l=apache-modperl&m=102874705105904&w=2
> 

cool.  you might want to check these out too

http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=102891528030133&w=2
http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=102902480103484&w=2

--Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org