The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ham::Packet::DXSpider - Receives DX Spots from the DXCluster

SYNOPSIS

    # Construct object using address and optional port  
    my $dx=Ham::Packet::DXSpider->new( 
        callsign => 'your callsign', 
        address => 'dxcluster address', 
        port => 'port', 
    );

    # Construct object using supplied IO::Handle
    my $dx=Ham::Packet::DXSpider->new( 
        callsign => 'your callsign', 
        handle => IO::Handle 
    );

    # Set a handler for received private messages
    $dx->addPrivateMessageHandler( sub {
        my %args=@_;
        my $from=       $args{from} || '';
        my $to=         $args{to}       || '';
        my $body=       $args{body}     || 'no message';
        my $subject=    $args{subject}  || 'no subject';
        my $time=       $args{time}     || gmtime(time());
    } );

    # Set a handler for received DX messages
    $dx->addDXMessageHandler( sub {
        my %args=@_;
        my $from=       $args{from};
        my $frequency=  $args{frequency};
        my $message=    $args{message};
        my $heard=      $args{heard};
        my $time=       $args{time};
        my $locator=    $args{locator};
    } );

    # Add a handler for collecting statistics on DX spots received.
    $dx->addStatsHandler( sub {
        my %args=@_;
        my $from=       $args{from};
        my $freq=       $args{frequency};
        my $message=    $args{message};
        my $heard=      $args{heard};
        my $time=       $args{time};
        my $locator=    $args{locator};
    } );

    # Send a message
    $dx->sendPrivate( $to, $subject, $message );

    $dx->start();

DESCRIPTION

CONSTRUCTOR

new( callsign => 'your callsign', address => 'dxcluster address', port => 'port', handle => IO::Handle );

Create a new DXSpider object for the specified callsign. If address and optionally port are specified, this will also open the connection to the DXSPIDER server.

Address can also be an already open IO::Handle object, in which case port becomes meaningless.

METHODS

BUILD()

Moose builder. Called after construction. Opens the handle if necessary.

open()

Opens a connection to a DXSPIDER server located at the address and port specified. Address can also be an already open IO::Handle object, in which case port becomes meaningless.

addStatsHandler( $codeRef )

Adds a code reference to a function that can be used to collect statistics of the received DX spot messages. Only DX spot messages will be sent to this handler.

Handlers are added to a list and will be called in turn when a new DX spot message arrives.

addDXMessageHandler( $codeRef )

Adds a code reference to a function that handles DX spot messages. Handlers are added to a list and will be called in turn when a DX spot message arrives.

addPrivateMessageHandler( $codeRef )

Adds a code reference to a function that handles Private messages directed to the logged in callsign. Handlers are added to a list and will be called in turn when a new message arrives.

start()

Continuously polls the DXSPIDER for new events. Returns if the handle for the connection closes or becomes undefined for whatever reason.

poll()

Polls the DXSPIDER once for a new event. This will block until something is received and the current transaction is completed.

TODO: Probably would be a candidate for a timeout when I get time.

sendPrivate( $to, $subject, $body )

Sends a private message to the callsign specified.

FUNCTIONS

Three functions are available for use as default handlers for testing and debugging purposes.

defaultDXMessageHandler()
defaultStatsHandler()
defaultPrivateMessageHandler()

Private Methods

dispatchStats()
dispatchDXMessage()
dispatchPrivateMessage()
_sendPrivate()
processPending()
process()

PREREQUISITES

IO::Handle
IO::Socket
IO::Socket::INET
Moose
POSIX
Test::More

OSNAMES

Unix or Unix-likes.

AUTHOR

Bruce James - custard@cpan.org

VERSION

0.04

COPYRIGHT

Copyright 2012, Bruce James

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.