Mailing List Archive

A try to patch Catalyst::Engine.pm
hi,

in version 5.7014, I changed a few lines of Engine.pm as below. Engine_1.pm
is the original and Engine.pm is the modified.

I did because of the warning "wide char..." when using test http server(in
Catalyst dist); some are in byte string and others are in character string
for output in my website.

by the way, where is the checkout info(svn checkout)?



--- ./Engine_1.pm 2008-04-06 11:29:11.000000000 -0400
+++ ./Engine.pm 2008-07-28 13:34:22.000000000 -0400
@@ -622,8 +622,12 @@
$self->{_prepared_write} = 1;
}

- my $len = length($buffer);
- my $wrote = syswrite STDOUT, $buffer;
+ my ( $len, $wrote );
+ {
+ use bytes;
+ $len = length($buffer);
+ $wrote = syswrite STDOUT, $buffer;
+ }

if ( !defined $wrote && $! == EWOULDBLOCK ) {
# Unable to write on the first try, will retry in the loop below
Re: A try to patch Catalyst::Engine.pm [ In reply to ]
* Chae Lee <yuand2@gmail.com> [2008-07-28 20:00]:
> my ( $len, $wrote );
> {
> use bytes;
> $len = length($buffer);
> $wrote = syswrite STDOUT, $buffer;
> }

Maybe like so?

my ( $len, $wrote ) = do {
use bytes;
length($buffer),
syswrite(STDOUT, $buffer);
};

Less repetition.

--
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: A try to patch Catalyst::Engine.pm [ In reply to ]
On Mon, Jul 28, 2008 at 01:56:52PM -0400, Chae Lee wrote:
> hi,
>
> in version 5.7014, I changed a few lines of Engine.pm as below. Engine_1.pm
> is the original and Engine.pm is the modified.
>
> I did because of the warning "wide char..." when using test http server(in
> Catalyst dist); some are in byte string and others are in character string
> for output in my website.
>
> by the way, where is the checkout info(svn checkout)?

http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Runtime/5.70/trunk

Also, you should try and create a test patch to prove your modification
works.

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: A try to patch Catalyst::Engine.pm [ In reply to ]
* On Mon, Jul 28 2008, Chae Lee wrote:
> hi,
>
> in version 5.7014, I changed a few lines of Engine.pm as below. Engine_1.pm is
> the original and Engine.pm is the modified.
>
> I did because of the warning "wide char..." when using test http server(in
> Catalyst dist); some are in byte string and others are in character string for
> output in my website.

Why are wide characters in the output buffer? The network cannot
transfer Perl wide characters; you need to convert them to bytes with
Encode::encode first. ("use bytes" is not acceptable.)

Catalyst::Plugin::Unicode automates this. Are you using that?

Regards,
Jonathan Rockway

--
print just => another => perl => hacker => if $,=$"

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: A try to patch Catalyst::Engine.pm [ In reply to ]
On Tue, Jul 29, 2008 at 10:29 AM, Jonathan Rockway <jon@jrock.us> wrote:

> * On Mon, Jul 28 2008, Chae Lee wrote:
> > hi,
> >
> > in version 5.7014, I changed a few lines of Engine.pm as below.
> Engine_1.pm is
> > the original and Engine.pm is the modified.
> >
> > I did because of the warning "wide char..." when using test http
> server(in
> > Catalyst dist); some are in byte string and others are in character
> string for
> > output in my website.
>
> Why are wide characters in the output buffer? The network cannot
> transfer Perl wide characters; you need to convert them to bytes with
> Encode::encode first. ("use bytes" is not acceptable.)


Yeah, I almost always use Encode.pm, but Engine.pm is special. it shouldn't
bother 'output'; it should just copy the output to the web browser
byte-by-byte. To make sure "byte-by-byte" (perl implicitly tries encoding),
I injected "use bytes;"


Catalyst::Plugin::Unicode automates this. Are you using that?
>
>
I didn't consider of the plugin simply because of the name "Unicode." Today
I looked at the code. Good! but drawbacks:

1. the plugin deals with ONLY utf8.

2. effective ONLY on the test server in Catalyst dist. If I apply the plugin
to, say Lighttpd, it happens to be purely an overhead.
Re: A try to patch Catalyst::Engine.pm [ In reply to ]
* On Tue, Jul 29 2008, Chae Lee wrote:
> On Tue, Jul 29, 2008 at 10:29 AM, Jonathan Rockway <jon@jrock.us> wrote:
> Why are wide characters in the output buffer? The network cannot
> transfer Perl wide characters; you need to convert them to bytes with
> Encode::encode first. ("use bytes" is not acceptable.)
>
>
> Yeah, I almost always use Encode.pm, but Engine.pm is special. it shouldn't
> bother 'output'; it should just copy the output to the web browser
> byte-by-byte.

Exactly. This is why I asked "why are wide characters in the output
buffer". If your application is using characters outside of 7-bit ASCII
and it isn't encoding the characters itself, it is completely broken and
could stop working correctly at any time.

> To make sure "byte-by-byte" (perl implicitly tries encoding), I
> injected "use bytes;"

So you are saying you want to output a memory dump of Perl's internals
to the web browser? I don't know of any web browsers that will
understand that. (perl doesn't "implicitly try encoding", you are
assuming that an internal implementation detail is an actual perl
feature. It's not.)

> I didn't consider of the plugin simply because of the name "Unicode." Today I
> looked at the code.

How do you have wide characters in the output buffer if you're not using
Unicode?

> Good! but drawbacks:
>
> 1. the plugin deals with ONLY utf8.

And "use bytes" deals with Perl's internal representation, which is
subject to change in any minor release. Yes, sometimes it's UTF-8 now,
which is why "use bytes" sometimes works. But it's not guaranteed at
all, and will break when the string can be represented as
latin-1. Surely explicitly using utf-8 is better than outputting
whatever random data perl has in memory.

> 2. effective ONLY on the test server in Catalyst dist. If I apply the plugin
> to, say Lighttpd, it happens to be purely an overhead.

I don't think you understand how Unicode in Perl works. Please google
around and educate yourself. I (and others) have written volumes about
this.

Regards,
Jonathan Rockway

--
print just => another => perl => hacker => if $,=$"

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev