Net::Rendezvous::Publish - publish Rendezvous services


Net-Rendezvous-Publish documentation Contained in the Net-Rendezvous-Publish distribution.

Index


Code Index:

NAME

Top

Net::Rendezvous::Publish - publish Rendezvous services

SYNOPSIS

Top

 use Net::Rendezvous::Publish;
 my $publisher = Net::Rendezvous::Publish->new
   or die "couldn't make a Responder object";
 my $service = $publisher->publish(
     name => "My HTTP Server",
     type => '_http._tcp',
     port => 12345,
 );
 while (1) { $publisher->step( 0.01 ) }

DESCRIPTION

Top

METHODS

Top

new

Creates a new publisher handle

publish( %definition )

Returns a Net::Rendezvous::Publish::Service object. The following keys are meaningful in the service definition hash.

name

A descriptive name for the service.

type

The type of service. This is string of the form _service._protocol.

port

The port on which you're advertising the service. If you're not using a port (and instead just using mDNS as a way of propogating other service information) it's common practice to use 9 (the discard service)

domain

The domain in which to advertise a service. Defaults to local.

step( $seconds )

Spend at most $seconds seconds handling network events and updating internal state.

At some point I may learn enough of the mDNS protocol to write a pure-perl responder. That'll be nifty.

AUTHOR

Top

Richard Clamp <richardc@unixbeard.net>

COPYRIGHT

Top

SEE ALSO

Top

Net::Rendezous - for service browsing.

Net::Rendezvous::Publish::Backend::* - you'll need one of these to talk to your local mDNS responder.


Net-Rendezvous-Publish documentation Contained in the Net-Rendezvous-Publish distribution.

package Net::Rendezvous::Publish;
use strict;
use warnings;
use Net::Rendezvous::Publish::Service;

use Module::Pluggable
  search_path => [ "Net::Rendezvous::Publish::Backend" ],
  sub_name    => 'backends';

use base qw( Class::Accessor::Lvalue );
__PACKAGE__->mk_accessors(qw( _backend _published ));

our $VERSION = 0.04;

sub new {
    my $class = shift;
    my %args = @_;

    my $self = $class->SUPER::new;

    my ($backend) = $args{backend} || (grep !/::Null$/, $self->backends)[0];
    $backend ||= "Net::Rendezvous::Publish::Backend::Null";

    eval "require $backend" or die $@;
    return unless $backend;
    $self->_backend = $backend->new
      or return;
    $self->_published = [];
    return $self;
}

sub publish {
    my $self = shift;
    my $service = Net::Rendezvous::Publish::Service->new;
    $service->_session = $self;
    $service->_handle  = $self->_backend->publish( object => $service, @_ )
      or return;
    return $service;
}

sub step {
    my $self = shift;
    $self->_backend->step( shift );
    return $self;
}


1;

__END__