Alvis-Convert
view release on metacpan or search on metacpan
bin/alvisSource view on Meta::CPAN
#!/usr/bin/perl
# Feeds docs from DIR/*.xml into the pipelineT. Wait minutes before each send.
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use Alvis::Pipeline;
# use Data::Dumper;
use encoding 'utf8';
use open ':utf8';
binmode STDIN, ":utf8";
binmode STDERR, ":utf8";
my $PIPE_WRITEPORT=0;
my $PIPE_WRITEHOST="localhost";
my $verbose = 0;
my ( @dirs, $sleep, $shutdown, $host, $port );
$host = 'localhost';
$port = 10000;
$shutdown = 0;
$sleep = 0;
GetOptions(
'man' => sub { pod2usage( -exitstatus => 0, -verbose => 2 ) },
'shutdown' => \$shutdown,
'v' => sub { $verbose++; },
's|sleep=i' => \$sleep,
'o|host=s' => \$host,
'p|port=i' => \$port,
'h|help' => sub { pod2usage(1) },
'<>' => sub { push @dirs, @_ },
);
pod2usage( -message => "ERROR: dir is not specified" )
if ( $#dirs < 0 && !$shutdown );
my $out= new Alvis::Pipeline::Write(port => $port, host => $host)
or die "can't create write-pipe for port $host:$port : $!";
if ( $verbose ) {
print STDERR "Opened write-pipe for port $host:$port\n";
}
foreach my $dir ( @dirs ) {
opendir(XA,"$dir") or die "Cannot opendir $dir/: $!";
my $latest = 0;
while ( (my $file=readdir(XA)) ) {
if ( $file !~ /^\./ && $file =~ /\.xml$/ ) {
open(F,"<$dir/$file");
my $buf = join("",<F>);
close(F);
if ( $verbose ) {
print STDERR "Writing XML of size " . length($buf) . " from $dir/$file\n";
}
$out->write($buf);
sleep($sleep * 60);
}
}
closedir(XA);
}
if ( $shutdown ) {
$out->write("<shutdown/>");
}
$out->close();
1;
__END__
=pod
=head1 NAME
( run in 0.836 second using v1.01-cache-2.11-cpan-39bf76dae61 )