| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use utf8; |
|---|
| 5 | use POE; |
|---|
| 6 | use Encode; |
|---|
| 7 | use File::Spec; |
|---|
| 8 | use FindBin; |
|---|
| 9 | use Carp; |
|---|
| 10 | use Getopt::Long; |
|---|
| 11 | |
|---|
| 12 | use lib File::Spec->catfile( $FindBin::Bin, 'lib'); |
|---|
| 13 | |
|---|
| 14 | use Mobirc; |
|---|
| 15 | use Mobirc::Util; |
|---|
| 16 | use Mobirc::HTTPD; |
|---|
| 17 | use Mobirc::IRCClient; |
|---|
| 18 | use Mobirc::ConfigLoader; |
|---|
| 19 | |
|---|
| 20 | $SIG{__DIE__} = \&Carp::confess; |
|---|
| 21 | $SIG{INT} = sub { die "SIGINT!\n" }; |
|---|
| 22 | |
|---|
| 23 | my $daemonize_fg = false; |
|---|
| 24 | my $conffname = File::Spec->catfile($FindBin::Bin, 'config.yaml'); |
|---|
| 25 | my $version = false; |
|---|
| 26 | GetOptions( |
|---|
| 27 | 'daemonize' => \$daemonize_fg, |
|---|
| 28 | 'config=s' => \$conffname, |
|---|
| 29 | 'version' => \$version, |
|---|
| 30 | ) or die "Usage: $0 -c config.yaml"; |
|---|
| 31 | Getopt::Long::Configure("bundling"); # allows -c -v |
|---|
| 32 | |
|---|
| 33 | if ($version) { |
|---|
| 34 | print "Mobirc/$Mobirc::VERSION\n"; |
|---|
| 35 | exit; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | die "file does not exist: $conffname" unless -f $conffname; |
|---|
| 39 | |
|---|
| 40 | DEBUG "load config: $conffname"; |
|---|
| 41 | my $config = Mobirc::ConfigLoader->load($conffname); |
|---|
| 42 | |
|---|
| 43 | # set default vars. |
|---|
| 44 | $config->{irc}->{ping_delay} ||= 30; |
|---|
| 45 | $config->{irc}->{reconnect_delay} ||= 10; |
|---|
| 46 | $config->{httpd}->{charset} ||= 'cp932'; |
|---|
| 47 | $config->{httpd}->{root} ||= decode('utf8', '/'); |
|---|
| 48 | $config->{httpd}->{echo} = true unless exists $config->{httpd}->{echo}; |
|---|
| 49 | $config->{global}->{assets_dir} ||= File::Spec->catfile($FindBin::Bin, 'assets'); |
|---|
| 50 | $config->{httpd}->{cookie_expires} ||= '+3d'; |
|---|
| 51 | $config->{httpd}->{content_type} ||= 'text/html; charset=Shift_JIS'; |
|---|
| 52 | |
|---|
| 53 | # daemonize |
|---|
| 54 | if ( $daemonize_fg ) { |
|---|
| 55 | daemonize($config->{global}->{pid_fname}); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | Mobirc::IRCClient->init($config); |
|---|
| 59 | Mobirc::HTTPD->init($config); |
|---|
| 60 | $poe_kernel->run(); |
|---|
| 61 | |
|---|
| 62 | exit 0; |
|---|
| 63 | |
|---|
| 64 | __END__ |
|---|
| 65 | |
|---|
| 66 | =head1 SYNOPSIS |
|---|
| 67 | |
|---|
| 68 | mobirc config.yaml |
|---|
| 69 | |
|---|
| 70 | =head1 WARNINGS |
|---|
| 71 | |
|---|
| 72 | This program is still ALPHA QUALITY. Don't use at production environment. |
|---|
| 73 | |
|---|
| 74 | =head1 CONCEPT |
|---|
| 75 | |
|---|
| 76 | easy hack, easy maintenance, modern style, easy to use for perl hackers. |
|---|
| 77 | |
|---|
| 78 | =head1 DONE |
|---|
| 79 | |
|---|
| 80 | use Encode instead of Unicode::Japanese |
|---|
| 81 | rebirth channel list |
|---|
| 82 | internal string should be flagged utf8 |
|---|
| 83 | Perl critic clean |
|---|
| 84 | show_channel should use TT. |
|---|
| 85 | split irc client feature to IRCClient.pm instead of keitaric.pl |
|---|
| 86 | new name. |
|---|
| 87 | use YAML instead of AppConfig |
|---|
| 88 | dispatcher likes Sledge(HTTPD) |
|---|
| 89 | TT should in the assets dir? |
|---|
| 90 | cool uri |
|---|
| 91 | use TT at dispatch_index |
|---|
| 92 | templates should be configurable |
|---|
| 93 | use poe's heap instead of global variables ;-( |
|---|
| 94 | Makefile.PL |
|---|
| 95 | |
|---|
| 96 | =head1 TODO |
|---|
| 97 | |
|---|
| 98 | avoid warnings. |
|---|
| 99 | |
|---|
| 100 | =head1 supported phones |
|---|
| 101 | |
|---|
| 102 | au WIN |
|---|
| 103 | docomo foma |
|---|
| 104 | |
|---|
| 105 | that's all... |
|---|
| 106 | |
|---|
| 107 | =head1 HISTORY |
|---|
| 108 | |
|---|
| 109 | mobirc is based on 'keitairc,v 1.33 2007/10/16 23:44:55 morimoto'. |
|---|
| 110 | |
|---|
| 111 | =head1 LICENSE |
|---|
| 112 | |
|---|
| 113 | This program is covered by the GNU General Public License 2 |
|---|
| 114 | |
|---|