1# -*- perl -*-
2#
3#   This example implements a very simple server, let's call it
4#   CalcServer. Calculating is done by the 'Calculator' class,
5#   Calculator instances accept method calls like
6#
7#       my $result = $calculator->multiply(3, 4, 5);
8#
9
10require 5.004;
11use strict;
12
13use lib qw(blib/arch blib/lib);
14
15$| = 1;
16
17require Net::Daemon::Test;
18require RPC::PlServer::Test;
19require IO::Socket;
20
21
22package Calculator;
23
24sub new {
25    my $proto = shift;
26    my $self = { @_ };
27    bless($self, (ref($proto) || $proto));
28    $self;
29}
30
31sub add {
32    my $self = shift;
33    my $result = 0;
34    foreach my $arg (@_) { $result += $arg }
35    $result;
36}
37
38sub multiply {
39    my $self = shift;
40    my $result = 1;
41    foreach my $arg (@_) { $result *= $arg }
42    $result;
43}
44
45sub subtract {
46    my $self = shift;
47    die 'Usage: subtract($a, $b)'  if @_ != 2;
48    my $result = shift;
49    $result - shift;
50}
51
52sub divide {
53    my $self = shift;
54    die 'Usage: subtract($a, $b)'  if @_ != 2;
55    my $result = shift;
56    my $divisor = shift;
57    if (!$divisor) { die "Division by zero error" }
58    $result / $divisor;
59}
60
61
62package CalcServer;
63
64use vars qw($VERSION @ISA);
65
66$VERSION = '0.01';
67@ISA = qw(RPC::PlServer::Test);
68
69
70sub Version ($) {
71    return "CalcServer - A simple network calculator; 1998, Jochen Wiedmann";
72}
73
74
75package main;
76
77my $server = CalcServer->new({'pidfile' => 'none'}, \@ARGV);
78
79$server->Bind();
80
81