Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lilstevey (4628)

  (email not shown publicly)

  • Heinekin
  • Kro
  • Addlestones
  • Old Rosie
  • Thatchers
  • Strongbow
  • Erdinger
  • Guiness
  • Budvar
  • Leffe ( usually blond )
  • Various Real Ales when in premises suitable

Journal of lilstevey (4628)

Tuesday November 24, 2009
02:49 PM

tweetscale progress

[ #39940 ]

I started having a play over a week ago but haven't had the time to do much - I'll blog this and see if I get any time to go further.

This entry is brought to you by use v6; - a delightful experience.

Perl v6.0.0 required--this is only v5.8.9, stopped at line 1.

I've been doing statically typedish language for too long. Theres me leaping into introspection, when, for now, for the serverside of things, a simple bit of dynamic programming will suffice. Lets quickly knock out a simple server.
use v6;
use Server;
use TestClass;
use TestRole;

my $tc =;
my $r = TestRole;
my $a = clzz => $tc, rle => $r );

use v6;
use HTTP::Daemon;

class Server
   has $clzz;
   has $rle;

   method startServer() {
      my HTTP::Daemon $d .= new;
      say "see {$d.url}";
      while my HTTP::Daemon::ClientConn $c = $d.accept {
         while my HTTP::Request $r = $c.get_request {
            my $p = $r.url.path;
            my @p = split "\/",$p;
            my $m = pop @p;

            if ( $r.method eq 'GET' && $rle.can( $m ) ) {
            } else {
            warn "{$r.method} {$r.url.path}";

Thats as simple as $rle.can( $m ) && $c.send_response($clzz."$m"()) - though my first attempt was $clzz.$m() - which resulted in "invoke() not implemented in class 'Perl6Str'"

Now to see what can be done on the client...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Nice post. Just so you know, $x.$meth(...) is fine if $meth is actually a code reference rather than a method name. If you have a name, then you always need the quotes and to interpolate it. If you'd somehow got hold of a method itself (for example through .WALK or by introspection) then you could use the $x.$meth form though. They're distinguished syntactically (quote vs variable). So the error was just telling you that a string isn't something that can be invoked.

    Hope this helps!