Arc Forumnew | comments | leaders | submitlogin
12 points by awwaiid 6139 days ago | link | parent

I don't have fancy HTML-generation w/callbacks, but here goes:

  #!/usr/bin/perl
  use Continuity;
  Continuity->new->loop; # This starts the webserver
  sub main {
    my $request = shift;
    $request->print("<form><input type=text name=foo><input type=submit>");
    my $foo = $request->next->param('foo');
    $request->print("<a href='.'>Click Here</a>");
    $request->next->print("You said: $foo");
  }


4 points by ap 6137 days ago | link

Using Catalyst, a Perl version might look like this:

  package ArcChallenge;
  use strict;
  use Catalyst;
  use Catalyst::Action::REST;
  
  my @said;
  
  sub index : Action ActionClass('REST') {}
  
  sub index_GET {
      my ($self, $c) = @_;
      $c->res->body( "<form method=post><input name=said><input type=submit>" );
  }
  
  sub index_POST {
      my ($self, $c) = @_;
      my $n = push @said, $c->req->params->{said};
      $c->res->body( "<a href='/said/$n'>Click Here</a>" );
  }
  
  sub said : Regex('^said/(\d+)$') {
      my ($self, $c) = @_;
      $c->res->body( $said[ $c->req->captures->[0] - 1 ] );
  }
  
  __PACKAGE__->setup;
  
  1;
Bit clunky as yet, but work's underway to tersen up the syntax. (For anyone interested in how this will be implemented under the hood, the magic CPAN incantation is Devel::Declare. However it's a months-old work in progress so docs are minimal.) Once done it will remove most of the repeated boilerplate bits in the above code (eg. the assignments from @_ to unpack the parameters).

-----

2 points by hobbified 6132 days ago | link

  package CatArc;
  
  use strict;
  use warnings;
  
  use Catalyst qw/Session Session::Store::FastMmap Session::State::Cookie/;

  our $VERSION = '3.14159265359';
  
  __PACKAGE__->setup;
  
  sub index : Index { } # No need to do anything
  
  sub landing : Local {
    my ( $self, $c ) = @_;
    $c->flash->{said} = $c->req->params->{said};
  }
  
  sub display : Local { } # Do nothing
  
  sub end : ActionClass('RenderView') { } # Do a magical nothing.
  
  1;
Plus templates, for crying out loud. They exist for a reason. TT used for the sake of "everyone knows it": index.tt and landing.tt are as good as static, containing just a form and a link resp. display.tt contains "You said: [% c.flash.said %]".

-----

7 points by s3graham 6139 days ago | link

Perl, I missed you! That one's pretty.

-----