Yenta/D.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 105 CC 3 SCAR 13.0
CC
3
Cov
0%
daemon
12.0
new
2.0
BEGIN
2.0
CRAP 3.7
1 # -*- perl -*-
2  
3 # Copyright (c) 2010 AdCopy
4 # Author: Jeff Weisberg
5 # Created: 2010-May-12 15:57 (EDT)
6 # Function: yenta daemon
7 #
8 # $Id$
9  
10 package AC::Yenta::D;
11  
12 use AC::Daemon;
13 use AC::DC::IO { monitor => 'AC::Yenta::Stats' };
14 use AC::Yenta::Config;
15 use AC::Yenta::Debug;
16 use AC::Yenta::Stats;
17 use AC::Yenta::Monitor;
18 use AC::Yenta::Server;
19 use AC::Yenta::Status;
20 use AC::Yenta::Store;
21 use AC::Yenta::MySelf;
22 use AC::Yenta::NetMon;
23 use AC::Yenta::Store::BDBI;
24 use AC::Yenta::Store::SQLite;
25 # use AC::Yenta::Store::Tokyo;
26  
27 use strict;
28  
29 sub new {
30 my $class = shift;
31 my %p = @_;
32  
33 AC::Yenta::MySelf->customize( $p{class_myself} );
34 # ...
35  
36 return bless \$class, $class;
37 }
38  
39 sub daemon {
40 my $me = shift;
41 my $cfile = shift;
42 my $opt = shift; # foreground, debugall, persistent_id, argv
43  
44 die "no config file specified\n" unless $cfile;
45  
46 # configure
47 $AC::Yenta::CONF = AC::Yenta::Config->new(
48 $cfile, onreload => sub {
49 AC::Yenta::Store::configure();
50 });
51  
52  
53 initlog( 'yenta', (conf_value('syslog') || 'local5'), $opt->{debugall} );
54  
55 AC::Yenta::Debug->init( $opt->{debugall}, $AC::Yenta::CONF);
56 daemonize(5, 'yentad', $opt->{argv}) unless $opt->{foreground};
57 verbose("starting.");
58  
59  
60 $SIG{CHLD} = $SIG{PIPE} = sub{}; # ignore
61 $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = \&AC::DC::IO::request_exit; # abort
62  
63 # initialize subsystems
64 my $port = $opt->{port} || conf_value('port');
65  
66 AC::Yenta::MySelf->init( $port, $opt->{persistent_id} );
67 AC::Yenta::Store::configure();
68 AC::Yenta::Status::init( $port );
69 AC::Yenta::Monitor::init();
70 AC::Yenta::NetMon::init();
71 AC::DC::IO::TCP::Server->new( $port, 'AC::Yenta::Server' );
72 verbose("server started on tcp/$port");
73  
74  
75 # start "cronjobs"
76 AC::DC::Sched->new(
77 info => 'check config files',
78 freq => 30,
79 func => sub { $AC::Yenta::CONF->check() },
80 );
81  
82 run_and_watch(
83 ($opt->{foreground} || $opt->{debugall}),
84 \&AC::DC::IO::mainloop,
85 );
86 }
87  
88  
89 1;