Home Website Changes Log in Log out

AddTwo Example

This simple example prompts for $num1, prompts for $num2, and then displays their sum.

By default sessions are cookie-based, so that if you open this program in two windows at once things will act strangely. The alternative is to track the session through GET/POST params, which then allows each window to have its own session.

#!/usr/bin/perl

use strict;
use Continuity::Server::Simple;

my $server = Continuity::Server::Simple->new(port => 8081);

$server->loop;

sub main {
  $server->get_request;
  print qq{
    <form>
      Enter first number:
      <input type=text name=num><input type=submit>
    </form>
  };
  my $num1 = $server->get_request->params->{num};
  print qq{
    <form>
      Enter second number:
      <input type=text name=num><input type=submit>
    </form>
  };
  my $num2 = $server->get_request->params->{num};
  my $sum = $num1 + $num2;
  print qq{
    <h2>The sum of $num1 and $num2 is $sum!</h2>
  }
}