-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwikiclient
executable file
·57 lines (51 loc) · 1.35 KB
/
wikiclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#
# Copyright (c) 2013 Mitchell Cooper
# don't expect this to be pretty because it's just for testing dude
#
use warnings;
use strict;
use lib 'lib';
use Wikifier::Server;
# read the configuration page.
die "Please provide the configuration file as the first argument\n" unless @ARGV;
my $conf = Wikifier::Page->new(file_path => shift @ARGV);
my $err = $conf->parse;
die "Configuration error: $err\n" if $err;
# create a loop.
my $loop = IO::Async::Loop->new;
my $stream;
$loop->connect(
addr => {
family => 'unix',
socktype => 'stream',
path => $conf->get('server.socket.path')
},
on_stream => sub {
$stream = shift;
print "Connected to $stream\n";
$stream->configure(
on_read => sub {
my (undef, $buffref, $eof ) = @_;
while( $$buffref =~ s/^(.*\n)// ) {
print "-> $1";
}
die "EOF\n" if $eof;
}
);
$loop->add($stream);
},
on_connect_error => sub { die "connection error\n" }
);
$loop->add(IO::Async::Stream->new(
read_handle => \*STDIN,
on_read => sub {
my (undef, $buffref, $eof) = @_;
while( $$buffref =~ s/^(.*\n)// ) {
return unless $stream;
print "<- $1";
$stream->write($1);
}
}
));
$loop->run