#!/usr/bin/perl -I/usr/depot/lib/perl5
# See below for documentation.

require 5.000;
use Net::PSYC;
use Pod::Usage qw( pod2usage );

my $noargs = $#ARGV == -1;
use Getopt::Std;
getopt('tbm');

if ($opt_h) {
	pod2usage;
	exit;
}

$target = $opt_t || 'psyc://localhost:2244/';	# talk to local "listen" script
$method = $opt_m || '_data_bulk';

bind_uniform( $opt_b ) if $opt_b;

print STDERR <<X if $noargs and -t STDIN;
*** Insert a multiline message now.
*** Message will be sent when input is terminated by CTRL-D.
*** Message will be delivered by -m $method to -t $target.
*** Try -h for help or 'perldoc psyccat' for a manual.

X

my $d = '';
# i know there are better ways to do this..
$d .= $_ while <>;

go($d);
sleep 4;
exit;


sub go {
	my $a = shift;
	$rc = sendmsg ($target, $method, $a); # , { _kilroy => 'woz ere' } );
	die "send: $rc" if $rc;
}

__END__

=pod

=head1 NAME

psyccat - a simple tool to send an unnamed file via PSYC

=head1 SYNOPSIS

 psyccat [<options>] <file>
    or
 <command> | psyccat [<options>]
    or
 psyccat [<options>]

 Options:
	-t <uniform>	PSYC address to deliver message to
	-b <uniform>	PSYC address to bind to
	-m <method>	PSYC method to use instead of the default
	-h		Output this usage help message
	-q		Be quiet

=head1 DESCRIPTION

Behaves a bit like cat(1). By default it will collect
everything from files or stdin, then attempt to send it
in a single packet to a psyclisten running on the localhost.

=head1 CAVEATS

As long as Net::PSYC does not provide any encryption, you
should use this within a trustworthy local network or
as a localhost service.

Also, psyccat will encounter size limits if you decide to
bind to a UDP address.

=head1 AUTHORS

carlo von lynX.

=head1 COPYRIGHT

This program is free software, published under the Affero GNU Public
License. A disclaimer isn't necessary in my country, nor do I need
to mention the current year to assert a copyright.

