#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Encode;
use File::Spec::Functions;
use FindBin;
use Carp;
use Getopt::Long;

use lib catfile( $FindBin::Bin, 'lib');

use App::Mobirc;
use App::Mobirc::Util;

$SIG{INT} = sub { die "SIGINT!\n" };

my $daemonize_fg = false;
my $conffname = catfile($FindBin::Bin, 'config.yaml');
my $version = false;
GetOptions(
    'daemonize' => \$daemonize_fg,
    'config=s'  => \$conffname,
    'version'   => \$version,
) or die "Usage: $0 -c config.yaml";
Getopt::Long::Configure("bundling"); # allows -c -v

if ($version) {
    print "App::Mobirc/$App::Mobirc::VERSION\n";
    exit;
}

die "file does not exist: $conffname" unless -f $conffname;

DEBUG "load config: $conffname";
my $context = App::Mobirc->new($conffname);

# daemonize
if ( $daemonize_fg ) {
    daemonize($context->config->{global}->{pid_fname});
}

$context->run;

exit 0;

__END__

=head1 NAME

mobirc - modern IRC to HTTP gateway

=head1 SYNOPSIS

   mobirc --config config.yaml

=head1 CONCEPT

easy hack, easy maintenance, modern style, easy to use for perl hackers.

=head1 HISTORY

mobirc is based on 'keitairc,v 1.33 2007/10/16 23:44:55 morimoto'.

=head1 LICENSE

This program is covered by the GNU General Public License 2

