line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Slides; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32064
|
use version; our $VERSION = qv('0.0.8'); |
|
1
|
|
|
|
|
2501
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
96
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
267
|
|
8
|
1
|
|
|
1
|
|
7
|
use base 'Exporter'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
135
|
|
9
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
734
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( spawn_server ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Module implementation here |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _launch_server { |
17
|
0
|
|
|
0
|
|
|
my %config = %{$_[0]}; |
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Prepare and run |
20
|
0
|
0
|
|
|
|
|
if (!exists $config{talk}) { |
21
|
0
|
0
|
|
|
|
|
if (blessed $config{slides}) { |
22
|
0
|
|
|
|
|
|
$config{slide_show} = $config{slides}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
0
|
|
|
|
|
|
require WWW::Slides::SlideShow; |
26
|
0
|
|
|
|
|
|
$config{slide_show} = WWW::Slides::SlideShow->new(); |
27
|
0
|
|
|
|
|
|
$config{slide_show}->read($config{slides}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if (!exists $config{controller}) { |
31
|
0
|
|
|
|
|
|
require WWW::Slides::Controller::TCP; |
32
|
0
|
|
|
|
|
|
$config{controller} = |
33
|
|
|
|
|
|
|
WWW::Slides::Controller::TCP->new( |
34
|
|
|
|
|
|
|
port => $config{'controller_port'},); |
35
|
|
|
|
|
|
|
} ## end if (!exists $config{controller... |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
if ($config{debug} && !exists $config{logger}) { |
38
|
0
|
|
|
|
|
|
require WWW::Slides::BasicLogger; |
39
|
0
|
|
|
|
|
|
$config{logger} = |
40
|
|
|
|
|
|
|
WWW::Slides::BasicLogger->new(channel => \*STDERR); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Ensure a couple of defaults |
44
|
0
|
0
|
|
|
|
|
$config{accepts_detaches} = 1 |
45
|
|
|
|
|
|
|
unless exists $config{accepts_detaches}; |
46
|
0
|
|
0
|
|
|
|
$config{ping_interval} ||= 10; |
47
|
0
|
|
|
|
|
|
$config{port} = $config{http_port}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
require WWW::Slides::Talk; |
50
|
0
|
|
|
|
|
|
$config{talk} = WWW::Slides::Talk->new(%config); |
51
|
|
|
|
|
|
|
} ## end if (!exists $config{talk... |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Daemonise |
54
|
0
|
|
|
|
|
|
require POSIX; |
55
|
0
|
|
|
|
|
|
POSIX::setsid(); # not a must IMHO: or die "setsid: $!"; |
56
|
0
|
|
|
|
|
|
chdir '/'; |
57
|
0
|
|
|
|
|
|
close STDOUT; |
58
|
0
|
0
|
|
|
|
|
close STDERR unless $config{debug}; |
59
|
0
|
|
|
|
|
|
close STDIN; |
60
|
0
|
|
|
|
|
|
$SIG{PIPE} = 'IGNORE'; # For stray connections |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Run talk |
63
|
0
|
|
|
|
|
|
$config{talk}->run(); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
exit 0; |
66
|
|
|
|
|
|
|
} ## end sub _launch_server |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub spawn_server { |
69
|
0
|
|
|
0
|
1
|
|
my ($config_href) = @_; |
70
|
0
|
0
|
|
|
|
|
croak "expected HASH ref as input parameter" |
71
|
|
|
|
|
|
|
unless ref($config_href) eq 'HASH'; |
72
|
0
|
|
|
|
|
|
my %config = %$config_href; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# First, let's see if we have all we need, which is little |
75
|
0
|
0
|
|
|
|
|
if (!exists $config{talk}) { |
76
|
0
|
0
|
|
|
|
|
croak "nowhere to take the slides from, provide a 'slides' parameter" |
77
|
|
|
|
|
|
|
unless exists $config{slides}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
croak "please provide either a 'controller' or a 'controller_port'" |
80
|
|
|
|
|
|
|
unless exists($config{controller}) |
81
|
|
|
|
|
|
|
|| exists($config{controller_port}); |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
croak "please provide an 'http_port' to listen to" |
84
|
|
|
|
|
|
|
unless $config{http_port}; |
85
|
|
|
|
|
|
|
} ## end if (!exists $config{talk... |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Here the iato comes |
88
|
0
|
|
|
|
|
|
my $pid = fork(); |
89
|
0
|
0
|
|
|
|
|
die "could not fork(): $!" unless defined $pid; # error |
90
|
0
|
0
|
|
|
|
|
_launch_server($config_href) unless $pid; # child |
91
|
0
|
|
|
|
|
|
sleep(1); # father |
92
|
0
|
|
|
|
|
|
return $pid; |
93
|
|
|
|
|
|
|
} ## end sub spawn_server |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
96
|
|
|
|
|
|
|
__END__ |