I've mungled protocol/echo to do something fancier. Dunno whether it's
worth adding or not. It's only fun if you run it with -v, and we can
supply our own knowledge base to talk our way :)

% ./t/TEST -v protocol/eliza
setting ulimit to allow core files
ulimit -c unlimited
 exec ./t/TEST -v protocol/eliza
/home/stas/httpd-2.0/sbin/httpd  -d /home/stas/apache.org/modperl-2.0/t -f
/home/stas/apache.org/modperl-2.0/t/conf/httpd.conf -DAPACHE2
using Apache/2.0.26-dev (prefork MPM)
waiting for server to warm up......ok
server localhost:8529 started (pid=24446)
server localhost:8530 listening (TestProtocol::echo)
server localhost:8531 listening (TestProtocol::eliza)
server localhost:8532 listening (TestProtocol::echo_filter)
server localhost:8533 listening (TestFilter::input_msg)
protocol/eliza......1..6
ok 1
SEND ='hello, Eliza'
REPLY='Hi. What seems to be your problem?'
ok 2
SEND ='how are you'
REPLY='Oh, I?'
ok 3
SEND ='why do I have core dumped?'
REPLY='Why do you say why do you have core dumped?'
ok 4
SEND ='I feel like writing some tests today, you?'
REPLY='Please go on.'
ok 5
SEND ='good bye'
REPLY='Does talking about this bother you?'
ok 6
ok
All tests successful.
Files=1, Tests=6,  1 wallclock secs ( 0.79 cusr +  0.10 csys =  0.89 CPU)
server localhost:8529 shutdown (pid=24446)

I thought to come up with some fancy infobot stuff, but alas it's not
being developed anymore :( But it'll be much fancier to use some bot to
demonstrate at Doug's talks, rather than silly command server :)

anyways, here is the patch (you need Chatbot::Eliza to be installed):

--- /dev/null   Sat Apr 14 19:06:21 2001
+++ t/protocol/eliza.t  Wed Sep  5 16:07:00 2001
@@ -0,0 +1,27 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestRequest ();
+
+use constant HAS_ELIZA => eval { require Chatbot::Eliza;};
+
+my @test_strings = ('hello, Eliza',
+                    'how are you',
+                    'why do I have core dumped?',
+                    'I feel like writing some tests today, you?',
+                    'good bye');
+
+plan tests => 1 + @test_strings, ['eliza'] && \&HAS_ELIZA;
+
+my $socket = Apache::TestRequest::vhost_socket('TestProtocol::eliza');
+
+ok $socket;
+
+for (@test_strings) {
+    print "SEND ='$_'\n";
+    print $socket "$_\n";
+    chomp(my $reply = <$socket>);
+    print "REPLY='$reply'\n";
+    ok $reply;
+}

--- /dev/null   Sat Apr 14 19:06:21 2001
+++ t/protocol/TestProtocol/eliza.pm    Wed Sep  5 15:53:00 2001
@@ -0,0 +1,31 @@
+package TestProtocol::eliza;
+
+use strict;
+use Apache::Connection ();
+use APR::Socket ();
+require Chatbot::Eliza;
+
+use constant BUFF_LEN => 1024;
+my $mybot = new Chatbot::Eliza;
+
+sub handler {
+    my Apache::Connection $c = shift;
+    my APR::Socket $socket = $c->client_socket;
+
+    my $buff;
+    my $last = 0;
+    for (;;) {
+        my($rlen, $wlen);
+        my $rlen = BUFF_LEN;
+        $socket->recv($buff, $rlen);
+        last if $rlen <= 0;
+        $last++ if $buff eq 'good bye';
+        $buff = $mybot->transform( $buff ) . "\n";
+        $socket->send($buff, length $buff);
+        last if $last;
+    }
+
+    return 0;
+}
+
+1;



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



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

Reply via email to