HTTP::Server::Simple::Bonjour - Bonjour plugin for HTTP::Server::Simple


HTTP-Server-Simple-Bonjour documentation Contained in the HTTP-Server-Simple-Bonjour distribution.

Index


Code Index:

NAME

Top

HTTP::Server::Simple::Bonjour - Bonjour plugin for HTTP::Server::Simple

SYNOPSIS

Top

  package MyServer;
  # You need to put ::Bonjour first so NEXT can work properly
  use base qw( HTTP::Server::Simple::Bonjour HTTP::Server::Simple::CGI );

  sub service_name { "My awesome webserver" }

  MyServer->new->run;

DESCRIPTION

Top

HTTP::Server::Simple::Bonjour is an HTTP::Server::Simple plugin to publish the server name and TCP port via Bonjour so anyone in the local network can discover your web server.

METHODS

Top

service_name

This method returns the name of the webserver your server wants to advertise

service_type

This method returns the bonjour service for your application. Most HTTP servers can safely leave this untouched. Override it and return something of the form '_http._tcp' if you need to.

AUTHOR

Top

Tatsuhiko Miyagawa <miyagawa@cpan.org>

Jesse Vincent

LICENSE

Top

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

SEE ALSO

Top

HTTP::Server::Simple Net::Rendezvous::Publish


HTTP-Server-Simple-Bonjour documentation Contained in the HTTP-Server-Simple-Bonjour distribution.

package HTTP::Server::Simple::Bonjour;

use strict;
use 5.8.1;
our $VERSION = '0.02';

use Carp;
use NEXT;

my $publisher = eval {
    require Net::Rendezvous::Publish;
    Net::Rendezvous::Publish->new;
};

sub print_banner {
    my $self = shift;

    unless ($publisher) {
        carp "Publisher backend is not available. Install one of Net::Rendezvous::Publish::Backend modules from CPAN.";
        $self->NEXT::print_banner;
        return;
    }

    $publisher->publish(
        name => $self->service_name,
        type => $self->service_type,
        port => $self->port,
        domain => 'local',
    );

    $self->NEXT::print_banner;
}

sub service_name {
    my $self = shift;
    require Sys::Hostname;
    return Sys::Hostname::hostname();
}


sub service_type { '_http._tcp' }


1;
__END__