#!/usr/bin/env perl
use
5.010001;
our
$VERSION
=
'0.47'
;
my
@base
= ( splitdir( dirname(__FILE__) ),
'..'
);
my
$dev
= -e catdir(
@base
,
't'
);
my
$lib
=
join
(
'/'
,
@base
,
'lib'
);
$dev
?
unshift
(
@INC
,
$lib
) :
push
(
@INC
,
$lib
);
my
$host
=
"*"
;
my
$port
;
my
$opt_version
;
my
$help
;
my
$result
= GetOptions(
"host=s"
=> \
$host
,
"port=i"
=> \
$port
,
"help"
=> \
$help
,
"version"
=> \
$opt_version
,
);
if
(
$help
) {
print
<<HELP;
Usage: farabi [switches]
help Shows this page
host HTTP hostname (default is *)
port HTTP port. It is port 4040 when CPAN-installed otherwise it is 3000
version Shows Farabi version
HELP
exit
;
}
if
(
$opt_version
) {
my
$version
;
if
(
open
my
$fh
,
"<"
,
"dist.ini"
) {
while
(
my
$line
= <
$fh
> ) {
if
(
$line
=~ /^version\s*=\s*(\S+)/ ) {
$version
=
"$1 (unreleased)"
;
}
}
close
$fh
;
}
$version
=
$version
// (
$Farabi::VERSION
||
'unreleased'
);
say
"Farabi v$version"
;
exit
;
}
$port
=
$port
// (
$dev
? 3000 : 4040);
say
"Farabi trying to listen at http://$host:$port"
;
Mojolicious::Commands->start_app(
'Farabi'
,
'daemon'
,
'-l'
,