Net-Signalet
view release on metacpan or search on metacpan
lib/Net/Signalet/script.pm view on Meta::CPAN
package Net::Signalet::script;
use strict;
use warnings;
use Carp ();
use Getopt::Long qw(:config no_ignore_case pass_through);
use Term::ANSIColor;
use Net::Signalet::Server;
use Net::Signalet::Client;
sub new {
my $class = shift;
my $self = bless {
argv => [],
verbose => undef,
server => undef,
client => undef,
daddr => undef,
saddr => undef,
port => undef,
}, $class;
return $self;
}
sub parse_options {
my $self = shift;
local @ARGV = @{$self->{argv}};
push @ARGV, @_;
Getopt::Long::Configure("bundling");
Getopt::Long::GetOptions(
'h|help' => sub { $self->{action} = 'show_help' },
'v|verbose' => sub { $self->{verbose} = 1 },
's|server' => sub { $self->{server} = 1 },
'c|client=s' => sub { $self->{client} = 1; $self->{daddr} = $_[1] },
'p|port=i' => \$self->{port},
'b|bind=s' => \$self->{saddr},
'V|version' => sub { $self->{action} = 'show_version' },
);
$self->{argv} = \@ARGV;
}
sub show_version {
print "signalet (Net::Signalet) version $Net::Signalet::VERSION\n";
return 1;
}
sub show_help {
my $self = shift;
if ($_[0]) {
die <<USAGE;
Usage: signalet [options] Target command
Try `signalet --help` for more options.
USAGE
}
print <<HELP;
Usage: signalet [options] command
Options:
-v,--verbose Turns on detailed output
-s,--server Server mode
-c,--client <ipaddr> Client mode
-p,--port n Set server port to listen on/connect to to n (default 14550)
-b,--bind Bind local address
Commands:
-V,--version Displays software version
HELP
return 1;
}
sub do {
my $self = shift;
if (my $action = $self->{action}) {
$self->$action() and return 1;
}
if (!$self->{server} && !$self->{client} or
$self->{server} && $self->{client})
{
$self->show_help(1);
( run in 0.648 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )