IPC-Filter-0.004000755001750001750 011610575567 13323 5ustar00zeframzefram000000000000IPC-Filter-0.004/META.yml000444001750001750 150311610575562 14723 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.38, CPAN::Meta::Converter version 2.110930001' 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.004 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: license: http://dev.perl.org/licenses/ version: 0.004 IPC-Filter-0.004/SIGNATURE000644001750001750 260411610575567 14750 0ustar00zeframzefram000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.68. 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 58964330f63a3e8ff13e1d37934c4d44b2a5d232 .cvsignore SHA1 13a583b49b245a0c188241c132f1dfe2ba1921c2 Build.PL SHA1 5e4e08d9452a8ea9d9273e3f95c8b4f66604603d Changes SHA1 5f63a6a7cda7149ab7188774d8f6372b078a86cc MANIFEST SHA1 0d39acd04b8201bca155bd3930a618168c50f8fd META.json SHA1 311ecc6f1c929a947c6a10903afde67655cae0db META.yml SHA1 a4df8e97ccd390a42212af5a9f4d0986c85e7a5f Makefile.PL SHA1 2782ca177a0dce5af51a665ccaf33719f0f8074c README SHA1 f1bd0b24241681e774033bd541f302ce06a1f64f 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.4.10 (GNU/Linux) iEYEARECAAYFAk4i+3IACgkQOV9mt2VyAVFQAACdH+J5IvAgscx43yCqQthRPiXC kZMAoKWFaMGfpijewie2JKUNcGr01l/Y =NEcR -----END PGP SIGNATURE----- IPC-Filter-0.004/MANIFEST000444001750001750 25111610575562 14562 0ustar00zeframzefram000000000000.cvsignore Build.PL Changes MANIFEST META.json META.yml Makefile.PL 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.004/Changes000444001750001750 221511610575562 14746 0ustar00zeframzefram000000000000version 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.004/README000444001750001750 103211610575562 14327 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 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.004/Makefile.PL000444001750001750 230211610575562 15422 0ustar00zeframzefram000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.3800 require 5.006; unless (eval "use Module::Build::Compat 0.02; 1" ) { print "This module requires Module::Build to install itself.\n"; require ExtUtils::MakeMaker; my $yn = ExtUtils::MakeMaker::prompt (' Install Module::Build now from CPAN?', 'y'); unless ($yn =~ /^y/i) { die " *** Cannot install without Module::Build. Exiting ...\n"; } require Cwd; require File::Spec; require CPAN; # Save this 'cause CPAN will chdir all over the place. my $cwd = Cwd::cwd(); CPAN::Shell->install('Module::Build::Compat'); CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate or die "Couldn't install Module::Build, giving up.\n"; chdir $cwd or die "Cannot chdir() back to $cwd: $!"; } eval "use Module::Build::Compat 0.02; 1" or die $@; Module::Build::Compat->run_build_pl(args => \@ARGV); my $build_script = 'Build'; $build_script .= '.com' if $^O eq 'VMS'; exit(0) unless(-e $build_script); # cpantesters convention require Module::Build; Module::Build::Compat->write_makefile(build_class => 'Module::Build'); IPC-Filter-0.004/.cvsignore000444001750001750 15011610575562 15427 0ustar00zeframzefram000000000000Build Makefile _build blib META.json META.yml MYMETA.json MYMETA.yml Makefile.PL SIGNATURE IPC-Filter-* IPC-Filter-0.004/META.json000444001750001750 300311610575562 15070 0ustar00zeframzefram000000000000{ "abstract" : "filter data through an external process", "author" : [ "Andrew Main (Zefram) " ], "dynamic_config" : 0, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110930001", "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.004" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.004" } IPC-Filter-0.004/Build.PL000444001750001750 143211610575562 14747 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" }, create_makefile_pl => "passthrough", sign => 1, )->create_build_script; 1; IPC-Filter-0.004/lib000755001750001750 011610575562 14064 5ustar00zeframzefram000000000000IPC-Filter-0.004/lib/IPC000755001750001750 011610575562 14477 5ustar00zeframzefram000000000000IPC-Filter-0.004/lib/IPC/Filter.pm000444001750001750 1010311610575562 16432 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.004"; 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 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.004/t000755001750001750 011610575562 13561 5ustar00zeframzefram000000000000IPC-Filter-0.004/t/pod_cvg.t000444001750001750 27311610575562 15506 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.004/t/filter.t000444001750001750 210211610575562 15363 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.004/t/pod_syn.t000444001750001750 23611610575562 15537 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;