IPC-Filter-0.005000755001750001750 013143442600 13304 5ustar00zeframzefram000000000000IPC-Filter-0.005/.gitignore000444001750001750 16313143442572 15421 0ustar00zeframzefram000000000000/Build /Makefile /_build /blib /META.json /META.yml /MYMETA.json /MYMETA.yml /Makefile.PL /SIGNATURE /IPC-Filter-* IPC-Filter-0.005/Build.PL000444001750001750 173613143442572 14754 0ustar00zeframzefram000000000000{ use 5.006; } use warnings; use strict; use Module::Build; Module::Build->new( module_name => "IPC::Filter", license => "perl", configure_requires => { "Module::Build" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, build_requires => { "Module::Build" => "0.2808", "Test::More" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, requires => { "Errno" => "1.00", "Exporter" => 0, "IO::Handle" => "1.12", "IO::Poll" => "0.01", "IPC::Open3" => "1.01", "IPC::Signal" => "1.00", "POSIX" => 0, "Symbol" => 0, "parent" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, dynamic_config => 0, meta_add => { distribution_type => "module" }, meta_merge => { "meta-spec" => { version => "2" }, resources => { bugtracker => { mailto => "bug-IPC-Filter\@rt.cpan.org", web => "https://rt.cpan.org/Public/Dist/". "Display.html?Name=IPC-Filter", }, }, }, sign => 1, )->create_build_script; 1; IPC-Filter-0.005/Changes000444001750001750 261513143442572 14750 0ustar00zeframzefram000000000000version 0.005; 2017-08-12 * no longer include a Makefile.PL in the distribution * in documentation, use four-column indentation for all verbatim material * in META.{yml,json}, point to public bug tracker * convert .cvsignore to .gitignore version 0.004; 2011-07-17 * revise signal test to avoid shell signal trapping * include META.json in distribution * add MYMETA.json to .cvsignore version 0.003; 2010-07-23 * revise tests to work with funny SysV tr and false * use simpler "parent" pragma in place of "base" * check for required Perl version at runtime * use full stricture in test suite * use full stricture in Build.PL * in Build.PL, explicitly declare configure-time requirements * remove bogus "exit 0" from Build.PL * add MYMETA.yml to .cvsignore version 0.002; 2007-09-17 * bugfix: override any ambient $SIG{__DIE__} handler when using eval { } * use "base" pragma to import Exporter behaviour * on non-Unix OSes, skip tests that rely on Unix commands * test POD syntax and coverage * corrected synopsis * build with Module::Build instead of ExtUtils::MakeMaker * complete dependency list * include signature in distribution * in documentation, separate "license" section from "copyright" section version 0.001; 2004-10-29 * include copyright notice in lib/IPC/Filter.pm version 0.000; 2004-10-29 * initial released version IPC-Filter-0.005/MANIFEST000444001750001750 23513143442572 14562 0ustar00zeframzefram000000000000.gitignore Build.PL Changes MANIFEST META.json META.yml README lib/IPC/Filter.pm t/filter.t t/pod_cvg.t t/pod_syn.t SIGNATURE Added here by Module::Build IPC-Filter-0.005/META.json000444001750001750 331213143442572 15071 0ustar00zeframzefram000000000000{ "abstract" : "filter data through an external process", "author" : [ "Andrew Main (Zefram) " ], "dynamic_config" : 0, "generated_by" : "Module::Build version 0.4224", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "IPC-Filter", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.2808", "Test::More" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "runtime" : { "requires" : { "Errno" : "1.00", "Exporter" : "0", "IO::Handle" : "1.12", "IO::Poll" : "0.01", "IPC::Open3" : "1.01", "IPC::Signal" : "1.00", "POSIX" : "0", "Symbol" : "0", "parent" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } } }, "provides" : { "IPC::Filter" : { "file" : "lib/IPC/Filter.pm", "version" : "0.005" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-IPC-Filter@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=IPC-Filter" }, "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.005", "x_serialization_backend" : "JSON::PP version 2.93" } IPC-Filter-0.005/META.yml000444001750001750 176713143442572 14735 0ustar00zeframzefram000000000000--- abstract: 'filter data through an external process' author: - 'Andrew Main (Zefram) ' build_requires: Module::Build: '0.2808' Test::More: '0' perl: '5.006' strict: '0' warnings: '0' configure_requires: Module::Build: '0' perl: '5.006' strict: '0' warnings: '0' dynamic_config: 0 generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: IPC-Filter provides: IPC::Filter: file: lib/IPC/Filter.pm version: '0.005' requires: Errno: '1.00' Exporter: '0' IO::Handle: '1.12' IO::Poll: '0.01' IPC::Open3: '1.01' IPC::Signal: '1.00' POSIX: '0' Symbol: '0' parent: '0' perl: '5.006' strict: '0' warnings: '0' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=IPC-Filter license: http://dev.perl.org/licenses/ version: '0.005' x_serialization_backend: 'CPAN::Meta::YAML version 0.012' IPC-Filter-0.005/README000444001750001750 104013143442572 14324 0ustar00zeframzefram000000000000NAME IPC::Filter - filter data through an external process DESCRIPTION The "filter" function provided by this module passes data through an external command, thus providing filtering in non-pipeline situations. INSTALLATION perl Build.PL ./Build ./Build test ./Build install AUTHOR Andrew Main (Zefram) COPYRIGHT Copyright (C) 2004, 2007, 2010, 2011, 2017 Andrew Main (Zefram) LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. IPC-Filter-0.005/SIGNATURE000644001750001750 247113143442600 14733 0ustar00zeframzefram000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.81. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 8ddab79d60f2121ee4900b0c92cf134831c4e6d9 .gitignore SHA1 76bc6c39445332372ce546dc4d6a08023b20ee9e Build.PL SHA1 678364eccb4971328e21b6fa1cafa97b97203320 Changes SHA1 b1116aff7f03eebce5e5305ebe763c31e984bc13 MANIFEST SHA1 4645e4cc910efecd11380a3bd66c26c5a2345083 META.json SHA1 158fe8903d292f9edcf7b10f9f20cac872cb6665 META.yml SHA1 4238c6999d2f09312704a340bb8a0eb3850907d7 README SHA1 005e8ce869fd9a0931a350caf00845207503fa5c lib/IPC/Filter.pm SHA1 100f79305a77fa34eb6ce806bc6ba9d070b949f7 t/filter.t SHA1 904d9a4f76525e2303e4b0c168c68230f223c8de t/pod_cvg.t SHA1 65c75abdef6f01a5d1588a307f2ddfe2333dc961 t/pod_syn.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlmORXoACgkQOV9mt2VyAVFzNwCfeQRk4rN+U+ME6TZ+r/xYIIAe oJIAoJOdWhY/7y092hxIwEgtLSwiS4hM =qRMz -----END PGP SIGNATURE----- IPC-Filter-0.005/lib000755001750001750 013143442572 14062 5ustar00zeframzefram000000000000IPC-Filter-0.005/lib/IPC000755001750001750 013143442572 14475 5ustar00zeframzefram000000000000IPC-Filter-0.005/lib/IPC/Filter.pm000444001750001750 1011713143442572 16435 0ustar00zeframzefram000000000000=head1 NAME IPC::Filter - filter data through an external process =head1 SYNOPSIS use IPC::Filter qw(filter); $compressed_data = filter($data, "bzip2"); =head1 DESCRIPTION The C function provided by this module passes data through an external command, thus providing filtering in non-pipeline situations. =cut package IPC::Filter; { use 5.006; } use warnings; use strict; use Errno 1.00 qw(EPIPE); use IPC::Open3 1.01 qw(open3); use IPC::Signal 1.00 qw(sig_name); use IO::Handle 1.12; use IO::Poll 0.01 qw(POLLIN POLLOUT POLLERR POLLHUP); use POSIX qw(_exit); use Symbol qw(gensym); our $VERSION = "0.005"; use parent "Exporter"; our @EXPORT_OK = qw(filter); =head1 FUNCTIONS =over =item filter(DATA, SHELL_COMMAND) =item filter(DATA, PROGRAM, ARGS ...) The SHELL_COMMAND, or the PROGRAM with ARGS if more arguments are supplied, is executed as a separate process. (The arguments other than DATA are ultimately passed to C; see L for explanation of the choice between the two forms.) The DATA (which must be either a simple string or a reference to a string) is supplied to the process on its standard input, and the process's standard output is captured and returned (as a simple string). If the process exits with a non-zero exit code or on a signal, the function will C. In the case of a non-zero exit code, the C message will duplicate the process's standard error output; in any other case, the error output is discarded. =cut my $chunksize = 4096; sub filter($@) { my $data = \shift(@_); if(@_ == 0 || $_[0] eq "-") { die "filter: invalid command\n"; } if(ref($data) eq "REF") { $data = $$data; } my $stdin = gensym; my $stdout = gensym; my $stderr = gensym; # Note: perl bug (bug in IPC::Open3 version 1.0106, bug ID # #32198): if the exec fails in the subprocess created by open3(), # it uses die() to emit its error message and terminate. If an # exception handler is installed using eval {}, execution in the # subprocess continues there instead of the process terminating. # We avoid nastiness by catching the exception ourselves and # doing the right thing. my $parent_pid = $$; my $child_pid = eval { local $SIG{__DIE__}; open3($stdin, $stdout, $stderr, @_); }; if($@ ne "") { my $err = $@; die $err if $$ == $parent_pid; print STDERR $err; _exit 255; } local $SIG{PIPE} = "IGNORE"; my $poll = IO::Poll->new; my $datalen = length($$data); if($datalen == 0) { $stdin->close; } else { $poll->mask($stdin => POLLOUT | POLLERR | POLLHUP); } $poll->mask($stdout => POLLIN | POLLERR | POLLHUP); $poll->mask($stderr => POLLIN | POLLERR | POLLHUP); my $datapos = 0; my @out; my @err; while($poll->handles) { $poll->poll; if($datapos != $datalen && $poll->events($stdin)) { my $n = $stdin->syswrite($$data, $chunksize, $datapos); if(defined $n) { $datapos += $n; } elsif($! == EPIPE) { $datapos = $datalen; } else { die "filter: stdin: $!\n"; } if($datapos == $datalen) { $poll->remove($stdin); $stdin->close; } } if($poll->events($stdout)) { my $output; unless(defined $stdout->sysread($output, $chunksize)) { die "filter: stdout: $!\n"; } if($output eq "") { $poll->remove($stdout); } else { push @out, $output; } } if($poll->events($stderr)) { my $output; unless(defined $stderr->sysread($output, $chunksize)) { die "filter: stderr: $!\n"; } if($output eq "") { $poll->remove($stderr); } else { push @err, $output; } } } waitpid $child_pid, 0; my $status = $?; if($status == 0) { return join("", @out); } if($status & 127) { die "filter: process died on SIG".sig_name($status & 127)."\n"; } else { die join("", "filter: process exited with status ", $status >> 8, "\n", @err); } } =back =head1 SEE ALSO L =head1 AUTHOR Andrew Main (Zefram) =head1 COPYRIGHT Copyright (C) 2004, 2007, 2010, 2011, 2017 Andrew Main (Zefram) =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; IPC-Filter-0.005/t000755001750001750 013143442572 13557 5ustar00zeframzefram000000000000IPC-Filter-0.005/t/filter.t000444001750001750 210213143442572 15361 0ustar00zeframzefram000000000000use warnings; use strict; use Module::Build 0.2808; use Test::More; BEGIN { plan skip_all => "these tests rely on Unix commands" unless Module::Build->is_unixish; plan tests => 14; use_ok "IPC::Filter", qw(filter); } my($result, $err); sub test_filter($@) { my($data, @cmd) = @_; $result = eval { filter($data, @cmd) }; $err = $@; } test_filter("foo\n"); is($err, "filter: invalid command\n"); test_filter("foo\n", "-"); is($err, "filter: invalid command\n"); test_filter("foo\n", "cat"); is($err, ""); is($result, "foo\n"); test_filter("foo\n", "tr", "abfor", "ABFOR"); is($err, ""); is($result, "FOO\n"); test_filter("foo\n", "tr abfor ABFOR"); is($err, ""); is($result, "FOO\n"); test_filter("foo\n", "tr abfor ABFOR; echo bar"); is($err, ""); is($result, "FOO\nbar\n"); test_filter("foo\n", "{ exit 1; }"); is($err, "filter: process exited with status 1\n"); test_filter("foo\n", "echo >&2 bar; exit 1"); is($err, "filter: process exited with status 1\nbar\n"); test_filter("foo\n", "echo >&2 bar; kill -9 \$\$"); is($err, "filter: process died on SIGKILL\n"); 1; IPC-Filter-0.005/t/pod_cvg.t000444001750001750 27313143442572 15504 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More; plan skip_all => "Test::Pod::Coverage not available" unless eval "use Test::Pod::Coverage; 1"; Test::Pod::Coverage::all_pod_coverage_ok(); 1; IPC-Filter-0.005/t/pod_syn.t000444001750001750 23613143442572 15535 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More; plan skip_all => "Test::Pod not available" unless eval "use Test::Pod 1.00; 1"; Test::Pod::all_pod_files_ok(); 1;