root/lang/perl/HTTP-Server-Simple-Bonjour/trunk/lib/HTTP/Server/Simple/Bonjour.pm @ 17232

Revision 17232, 1.4 kB (checked in by miyagawa, 5 years ago)

import HTTP::Server::Simple::Bonjour

Line 
1package HTTP::Server::Simple::Bonjour;
2
3use strict;
4use 5.8.1;
5our $VERSION = '0.01';
6
7use Carp;
8use NEXT;
9use Net::Rendezvous::Publish;
10
11my $publisher = eval { Net::Rendezvous::Publish->new };
12
13sub 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
31sub service_name {
32    my $self = shift;
33    require Sys::Hostname;
34    return Sys::Hostname::hostname();
35}
36
371;
38__END__
39
40=encoding utf-8
41
42=for stopwords
43
44=head1 NAME
45
46HTTP::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
59HTTP::Server::Simple::Bonjour is an HTTP::Server::Simple plugin to
60publish the server name and TCP port via Bonjour so anyone in the
61local network can discover your web server.
62
63=head1 AUTHOR
64
65Tatsuhiko Miyagawa E<lt>miyagawa@cpan.orgE<gt>
66
67=head1 LICENSE
68
69This library is free software; you can redistribute it and/or modify
70it under the same terms as Perl itself.
71
72=head1 SEE ALSO
73
74L<HTTP::Server::Simple> L<Net::Bonjour::Publish>
75
76=cut
Note: See TracBrowser for help on using the browser.