script/socialskk.pl untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 67 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use YAML::Syck;
5 use File::Spec;
6 use File::HomeDir;
7 use Getopt::Long;
8 use Sys::Hostname;
9 use Pod::Usage;
10 use POE qw(Component::Server::TCP Filter::Stream);
11  
12 use App::SocialSKK;
13  
14 my %options = (
15 config => File::Spec->catfile(File::HomeDir->my_home, '.socialskk'),
16 port => 1179,
17 address => '127.0.0.1',
18 hostname => Sys::Hostname::hostname(),
19 help => undef,
20 );
21  
22 GetOptions(
23 'config=s' => \$options{config},
24 'hostname=s' => \$options{hostname},
25 'address=s' => \$options{address},
26 'port=i' => \$options{port},
27 'help' => \$options{help},
28 );
29  
30 pod2usage(2) if $options{help};
31  
32 # use Social IME as a default backend
33 my $config = {
34 plugins => [
35 { name => 'SocialIME' },
36 ],
37 };
38  
39 $config = YAML::Syck::LoadFile($options{config}) if -e $options{config};
40 my $app = App::SocialSKK->new({(%options, config => $config)});
41  
42 POE::Component::Server::TCP->new(
43 Port => $options{port},
44 Address => $options{address},
45 Hostname => $options{hostname},
46 ClientFilter => POE::Filter::Stream->new,
47 ClientInput => sub {
48 my ($kernel, $heap, $input) = @_[KERNEL, HEAP, ARG0];
49 if ($input =~ /^0/) {
50 $kernel->yield('shutdown');
51 return;
52 }
53 my $result = $app->protocol->accept($input);
54 if (defined $result) {
55 $heap->{client}->put($result);
56 }
57 },
58 );
59  
60 POE::Kernel->run;
61 exit;
62  
63 __END__
64  
65 =head1 NAME
66  
67 socialskk.pl - Yet Another skkserv Implementation
68  
69 =head1 SYNOPSIS
70  
71 socialskk.pl [-c|config file] [-p|port number] [--help]
72  
73 Options:
74 -c --config: configuration file
75 -p --port : port number
76 --help : show usage
77  
78 =head1 DESCRIPTION
79  
80 socialskk.pl works as a SKK dictionary server which performs searches
81 for candidates and returns results along with requests from client.
82  
83 =head1 OPTIONS
84  
85 =over 4
86  
87 =item -c|--config
88  
89 Sets a path to configuration file. If not set, socialskk.pl tries to
90 load $HOME/.socialskk instead.
91  
92 =item -p|--port
93  
94 Sets a number of port used by the server.
95  
96 =item --help
97  
98 Shows this help document.
99  
100 =back
101  
102 =head1 AUTHOR
103  
104 Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
105  
106 =head1 COPYRIGHT AND LICENSE (The MIT License)
107  
108 Copyright (c) Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
109  
110 Permission is hereby granted, free of charge, to any person obtaining
111 a copy of this software and associated documentation files (the
112 "Software"), to deal in the Software without restriction, including
113 without limitation the rights to use, copy, modify, merge, publish,
114 distribute, sublicense, and/or sell copies of the Software, and to
115 permit persons to whom the Software is furnished to do so, subject to
116 the following conditions:
117  
118 The above copyright notice and this permission notice shall be
119 included in all copies or substantial portions of the Software.
120  
121 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
122 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
124 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
125 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
126 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
127 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
128  
129 =cut