|
Revision 17232, 1.4 kB
(checked in by miyagawa, 5 years ago)
|
|
import HTTP::Server::Simple::Bonjour
|
| Line | |
|---|
| 1 | package HTTP::Server::Simple::Bonjour; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use 5.8.1; |
|---|
| 5 | our $VERSION = '0.01'; |
|---|
| 6 | |
|---|
| 7 | use Carp; |
|---|
| 8 | use NEXT; |
|---|
| 9 | use Net::Rendezvous::Publish; |
|---|
| 10 | |
|---|
| 11 | my $publisher = eval { Net::Rendezvous::Publish->new }; |
|---|
| 12 | |
|---|
| 13 | sub print_banner { |
|---|
| 14 | unless ($publisher) { |
|---|
| 15 | carp "Publisher backend is not available. Install one of Net::Rendezvous::Publish::Backend modules from CPAN."; |
|---|
| 16 | return; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | my $self = shift; |
|---|
| 20 | |
|---|
| 21 | $publisher->publish( |
|---|
| 22 | name => $self->service_name, |
|---|
| 23 | type => '_http._tcp', |
|---|
| 24 | port => $self->port, |
|---|
| 25 | domain => 'local', |
|---|
| 26 | ); |
|---|
| 27 | |
|---|
| 28 | $self->NEXT::print_banner; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | sub service_name { |
|---|
| 32 | my $self = shift; |
|---|
| 33 | require Sys::Hostname; |
|---|
| 34 | return Sys::Hostname::hostname(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | 1; |
|---|
| 38 | __END__ |
|---|
| 39 | |
|---|
| 40 | =encoding utf-8 |
|---|
| 41 | |
|---|
| 42 | =for stopwords |
|---|
| 43 | |
|---|
| 44 | =head1 NAME |
|---|
| 45 | |
|---|
| 46 | HTTP::Server::Simple::Bonjour - Bonjour plugin for HTTP::Server::Simple |
|---|
| 47 | |
|---|
| 48 | =head1 SYNOPSIS |
|---|
| 49 | |
|---|
| 50 | package MyServer; |
|---|
| 51 | use base qw( HTTP::Server::Simple::Bonjour HTTP::Server::Simple::CGI ); |
|---|
| 52 | |
|---|
| 53 | sub server_name { "My awesome webserver" } |
|---|
| 54 | |
|---|
| 55 | MyServer->new->run; |
|---|
| 56 | |
|---|
| 57 | =head1 DESCRIPTION |
|---|
| 58 | |
|---|
| 59 | HTTP::Server::Simple::Bonjour is an HTTP::Server::Simple plugin to |
|---|
| 60 | publish the server name and TCP port via Bonjour so anyone in the |
|---|
| 61 | local network can discover your web server. |
|---|
| 62 | |
|---|
| 63 | =head1 AUTHOR |
|---|
| 64 | |
|---|
| 65 | Tatsuhiko Miyagawa E<lt>miyagawa@cpan.orgE<gt> |
|---|
| 66 | |
|---|
| 67 | =head1 LICENSE |
|---|
| 68 | |
|---|
| 69 | This library is free software; you can redistribute it and/or modify |
|---|
| 70 | it under the same terms as Perl itself. |
|---|
| 71 | |
|---|
| 72 | =head1 SEE ALSO |
|---|
| 73 | |
|---|
| 74 | L<HTTP::Server::Simple> L<Net::Bonjour::Publish> |
|---|
| 75 | |
|---|
| 76 | =cut |
|---|