SOAP: Simplying Distributed Development
by Neil Gunton

Listing One
#!/usr/local/bin/perl -w
use SOAP::Transport::HTTP;
my $daemon = SOAP::Transport::HTTP::Daemon
    -> new (LocalAddr => 'localhost', LocalPort => 81)
    -> objects_by_reference(qw(Spelling))
    -> dispatch_to('Spelling');
  print "Contact to SOAP server at ", $daemon->url, "\n";
  $daemon->handle;
package Spelling;
sub check
{
    my ($self, $text) = @_;
    use Lingua::Ispell;
    $Lingua::Ispell::path = "/usr/bin/ispell";
    $dummy = '__TERM__';
    for $word (Lingua::Ispell::spellcheck ($text))
    {
        if ($word->{type} eq 'miss' )
        {
            # First replace any terms found inside HTML or Embperl 
            #                                  brackets with dummy term
            $text =~ s{([\<\[])([^\>\]]*?)(\b$word->{term}\b)}{$1$2$dummy}g;

            # Now mark up the remaining terms with red font
            $text =~ s{(^|[^\>\&])(\b$word->{term}\b)}{$1\<FONT 
                                              COLOR=\"red\"\>$2\<\/FONT\>}g;
            # Restore the dummy terms
            $text =~ s{$dummy}{$word->{term}}g;
        }
    }
    return $text;
}
1;

Listing Two
sub check_spelling
{
        my ($self, $textref) = @_;

        # Check spelling
        use SOAP::Lite;
        my $soap = SOAP::Lite
           -> uri('http://localhost/Spelling')
           -> proxy('http://localhost:81')
           -> on_fault (sub {undef $result});
        $result = $soap->check($$textref);
        $$textref = $result ? $result->result() : $$textref;
}


2

