System-Sub-0.162800/0000775000175000017500000000000012775555647013334 5ustar dolmendolmenSystem-Sub-0.162800/MANIFEST0000644000175000017500000000067712775555647014475 0ustar dolmendolmen# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.005. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini examples/df.pl examples/zenity.pl lib/System/Sub.pm lib/System/Sub/AutoLoad.pm t/00-compile.t t/20-hostname.t t/21-AUTOLOAD.t t/22-ENV.t t/23-prototype.t t/24-error.t t/25-common-opts.t t/exiterr.pl t/print.pl t/printenv.pl xt/author/pod-coverage.t xt/author/pod-syntax.t xt/release/kwalitee.t System-Sub-0.162800/Makefile.PL0000644000175000017500000000300712775555647015304 0ustar dolmendolmen# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.005. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Wrap external command with a DWIM sub", "AUTHOR" => "Olivier Mengu\x{e9} ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "System-Sub", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "System::Sub", "PREREQ_PM" => { "Carp" => 0, "File::Which" => 0, "IPC::Run" => 0, "Scalar::Util" => "1.11", "Sub::Name" => 0, "Symbol" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => 0, "blib" => "1.01" }, "VERSION" => "0.162800", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "File::Spec" => 0, "File::Which" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "IPC::Run" => 0, "Scalar::Util" => "1.11", "Sub::Name" => 0, "Symbol" => 0, "Test::More" => 0, "blib" => "1.01", "constant" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); System-Sub-0.162800/META.yml0000644000175000017500000000146412775555647014610 0ustar dolmendolmen--- abstract: 'Wrap external command with a DWIM sub' author: - 'Olivier Mengué ' build_requires: File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::More: '0' blib: '1.01' perl: '5.006' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.006' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.005, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: System-Sub requires: Carp: '0' File::Which: '0' IPC::Run: '0' Scalar::Util: '1.11' Sub::Name: '0' Symbol: '0' constant: '0' perl: '5.006' strict: '0' warnings: '0' resources: homepage: https://github.com/dolmen/p5-System-Sub repository: https://github.com/dolmen/p5-System-Sub.git version: '0.162800' System-Sub-0.162800/examples/0000775000175000017500000000000012775555647015152 5ustar dolmendolmenSystem-Sub-0.162800/examples/df.pl0000755000175000017500000000044712775555647016106 0ustar dolmendolmen#!/usr/bin/env perl use 5.010; use strict; use warnings; use lib '../lib'; use System::Sub df => [ '%ENV' => { POSIXLY_CORRECT => 1 } ]; df sub { return if $. == 1; printf "%s: %s\n", (split / +/, $_[0])[5, 4]; #my @line = split / +/, $_[0]; #print "$line[5]: $line[4]\n"; }; System-Sub-0.162800/examples/zenity.pl0000755000175000017500000000102012775555647017023 0ustar dolmendolmen#!/usr/bin/env perl use lib '../lib'; use System::Sub 'zenity'; # The sub will die if status is not 0 # But exit status of zenity is 1 for the cancel button # so we have to catch that eval { zenity '--question', '--no-markup', '--title' => 'System::Sub test', '--text' => 'How are you today?', '--ok-label' => 'Fine!', '--cancel-label' => 'Tired.'; }; my $status = $? >> 8; print "$status\n"; if ($status == 0) { print "Great!\n" } elsif ($status == 1) { print "Have a nap!\n" } System-Sub-0.162800/META.json0000644000175000017500000000335512775555647014761 0ustar dolmendolmen{ "abstract" : "Wrap external command with a DWIM sub", "author" : [ "Olivier Mengu\u00e9 " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.005, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "System-Sub", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.006" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Kwalitee" : "1.21", "Test::More" : "0.88", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "File::Which" : "0", "IPC::Run" : "0", "Scalar::Util" : "1.11", "Sub::Name" : "0", "Symbol" : "0", "constant" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0", "blib" : "1.01", "perl" : "5.006" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/dolmen/p5-System-Sub", "repository" : { "type" : "git", "url" : "https://github.com/dolmen/p5-System-Sub.git", "web" : "https://github.com/dolmen/p5-System-Sub" } }, "version" : "0.162800" } System-Sub-0.162800/t/0000775000175000017500000000000012775555647013577 5ustar dolmendolmenSystem-Sub-0.162800/t/00-compile.t0000644000175000017500000000236512775555647015635 0ustar dolmendolmenuse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054 use Test::More; plan tests => 2 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'System/Sub.pm', 'System/Sub/AutoLoad.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; System-Sub-0.162800/t/20-hostname.t0000644000175000017500000000076012775555647016022 0ustar dolmendolmen use strict; use warnings; use Test::More (-x '/bin/hostname' ? (tests => 4) : (skip_all => 'No /bin/hostname')); use System::Sub hostname => [ '$0' => '/bin/hostname' ]; my $expected = `hostname`; chomp $expected; $_ = 'canary'; my $got = hostname; is($got, $expected, 'scalar context'); is($_, 'canary', '$_ not changed'); my @got = hostname; is_deeply(\@got, [ $expected ], 'list context'); is($_, 'canary', '$_ not changed'); # vim:set et sw=4 sts=4: System-Sub-0.162800/t/24-error.t0000644000175000017500000000070012775555647015333 0ustar dolmendolmenuse strict; use warnings; use Test::More tests => 8; use File::Spec; use System::Sub exiterr => [ 0 => $^X, ARGV => [ File::Spec->catfile(qw(t exiterr.pl)) ], '()' => '$', '&?' => sub { my ($name, $code, $cmd) = @_; is($name, 'exiterr', 'name'); is($cmd->[0], $^X, '$cmd[0]'); is($?, $code, '$code == $?'); is($? >> 8, $cmd->[2]); }, ]; exiterr 4; exiterr 5; # vim:set et sw=4 sts=4: System-Sub-0.162800/t/21-AUTOLOAD.t0000644000175000017500000000064212775555647015414 0ustar dolmendolmen use strict; use warnings; use Test::More (-x '/bin/hostname' ? (tests => 2) : (skip_all => 'No /bin/hostname')); { package cmd; use System::Sub::AutoLoad; } my $expected = `hostname`; chomp $expected; my $got = cmd::hostname(); is($got, $expected, 'scalar context'); my @got = cmd::hostname(); is_deeply(\@got, [ $expected ], 'list context'); # vim:set et sw=4 sts=4: System-Sub-0.162800/t/23-prototype.t0000644000175000017500000000162112775555647016251 0ustar dolmendolmen use strict; use warnings; use Test::More (-x '/bin/hostname' ? (tests => 8) : (skip_all => 'No /bin/hostname')); use System::Sub hostname => [ '$0' => '/bin/hostname' ], 'hostname_proto()' => [ '$0' => '/bin/hostname' ], 'hostname_proto2' => [ '()' => '', '$0' => '/bin/hostname' ]; my $expected = `hostname`; chomp $expected; my $got = hostname; is($got, $expected, 'scalar context'); is(prototype \&hostname, undef, 'prototype: undef'); $got = hostname_proto; is($got, $expected, 'scalar context'); is(prototype \&hostname_proto, '', 'prototype: ""'); is(scalar eval 'hostname_proto(1)', undef, 'call with arg fails'); like($@, qr/Too many arguments for main::hostname_proto at /, 'error "Too many arguments"'); $got = hostname_proto2; is($got, $expected, 'scalar context'); is(prototype \&hostname_proto2, '', 'prototype: ""'); # vim:set et sw=4 sts=4: System-Sub-0.162800/t/printenv.pl0000755000175000017500000000007112775555647016000 0ustar dolmendolmenuse strict; use warnings; print $ENV{$_}, $/ for @ARGV; System-Sub-0.162800/t/print.pl0000755000175000017500000000005112775555647015265 0ustar dolmendolmen#!/usr/bin/perl print $_, $/ for @ARGV; System-Sub-0.162800/t/exiterr.pl0000755000175000017500000000003512775555647015615 0ustar dolmendolmen#!/usr/bin/perl exit shift; System-Sub-0.162800/t/22-ENV.t0000644000175000017500000000104412775555647014632 0ustar dolmendolmenuse strict; use warnings; use Test::More tests => 2; use File::Spec; use System::Sub printenv => [ 0 => $^X, ARGV => [ File::Spec->catfile(qw(t printenv.pl)) ], ENV => { Toto => 'Titi', Lala => 'Lulu' }, ]; is(scalar printenv('Toto'), 'Titi', 'scalar context'); is_deeply([ printenv(qw(Toto Lala)) ], [ qw(Titi Lulu) ], 'list context'); # vim:set et sw=4 sts=4: System-Sub-0.162800/t/25-common-opts.t0000644000175000017500000000132412775555647016461 0ustar dolmendolmenuse strict; use warnings; use Test::More tests => 5; use File::Spec; # Test common options and prototypes use System::Sub [ 0 => $^X, ARGV => [ File::Spec->catfile(qw(t print.pl)) ] ], qw< print1($) print2($$) >, printenv => [ ENV => { Toto => 'Lulu' }, '--' => File::Spec->catfile(qw(t printenv.pl)), 'Toto' ]; is( scalar print1('x'), 'x', 'print1 (scalar)'); is_deeply([ print1('y') ], [ 'y' ], 'print1 (list)'); is( scalar print2('x', 'y'), 'x', 'print2 (scalar)'); is_deeply([ print2('x', 'y') ], [ qw< x y > ], 'print2 (list)'); is_deeply([ printenv ], [ 'Lulu' ], 'printenv Toto'); # vim:set et sw=4 sts=4: System-Sub-0.162800/lib/0000775000175000017500000000000012775555647014102 5ustar dolmendolmenSystem-Sub-0.162800/lib/System/0000775000175000017500000000000012775555647015366 5ustar dolmendolmenSystem-Sub-0.162800/lib/System/Sub/0000775000175000017500000000000012775555647016117 5ustar dolmendolmenSystem-Sub-0.162800/lib/System/Sub/AutoLoad.pm0000644000175000017500000000541512775555647020170 0ustar dolmendolmenuse strict; use warnings; package System::Sub::AutoLoad; $System::Sub::AutoLoad::VERSION = '0.162800'; use System::Sub (); sub _croak { require Carp; goto &Carp::croak } # Storage for sub options until they are installed with the AUTOLOAD my %AutoLoad; sub import { my $pkg = caller; shift; while (@_) { my $name = shift; _croak "invalid arg: SCALAR expected" unless defined ref $name && ! ref $name; my $fq_name = $pkg.'::'.$name; $AutoLoad{$fq_name} = shift if @_ && ref $_[0]; # Create a forward declaration that will be usable by the Perl # parser. See subs.pm no strict 'refs'; *{$fq_name} = \&{$fq_name}; } # Install the AUTOLOAD sub no strict 'refs'; *{$pkg.'::AUTOLOAD'} = \&_AUTOLOAD; } sub _AUTOLOAD { my $fq_name = our $AUTOLOAD; my $options = delete $AutoLoad{$fq_name}; System::Sub->import($fq_name, $options ? ($options) : ()); no strict 'refs'; goto &$fq_name } 1; __END__ =head1 NAME System::Sub::AutoLoad - Auto-wrap external commands as DWIM subs =head1 VERSION version 0.162800 =head1 SYNOPSIS =head2 Basic usage Any unknown sub will become a C>. use System::Sub::AutoLoad; my $hostname = hostname(); =head2 Usage with forward declaration Allows to avoid using parentheses. C> import stays lazy. use System::Sub::AutoLoad qw(hostname); my $hostname = hostname; =head2 Usage with forward declaration command options Options definitions will be checked lazily at the first call to the AUTOLOAD for that sub. use System::Sub::AutoLoad hostname => [ 0 => '/bin/hostname' ]; my $hostname = hostname; =head1 DESCRIPTION Any unknown sub in your code will be transformed into a C> at its first call. This is L import for C>. To avoid using parentheses after the sub name, you usually have to predeclare the sub with either a forward declaration (a sub without body such as C) or with the C> module. With C> you can simply list the subs names on the C line and that will be done for you. You can also pass C> options to the sub, but they will be lazily analysed: this is the full C> power, but with lazy import. =head2 Implementation details This module exports an L sub that will import the sub with C> at its first call. =head1 AUTHOR Olivier MenguE, C. =head1 COPYRIGHT & LICENSE Copyright E 2012 Olivier MenguE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. =cut # vim:set et sw=4 sts=4: System-Sub-0.162800/lib/System/Sub.pm0000644000175000017500000003124012775555647016453 0ustar dolmendolmenuse strict; use warnings; package System::Sub; $System::Sub::VERSION = '0.162800'; use File::Which (); use Sub::Name 'subname'; use Symbol 'gensym'; use IPC::Run qw(start finish); use Scalar::Util 1.11 (); # set_prototype(&$) appeared in 1.11 our @CARP_NOT; use constant DEBUG => !! $ENV{PERL_SYSTEM_SUB_DEBUG}; my %OPTIONS = ( # Value is the expected ref of the option value # undef is no value '>' => '', '<' => '', 'ENV' => 'HASH', '?' => 'CODE', ); sub _croak { require Carp; goto &Carp::croak } sub _carp { require Carp; goto &Carp::carp } sub import { my $pkg = (caller)[0]; shift; my $common_options; $common_options = shift if @_ && ref($_[0]) eq 'ARRAY'; while (@_) { my $name = shift; # Must be a scalar _croak "invalid arg: SCALAR expected" unless defined ref $name && ! ref $name; my ($fq_name, $proto); if ($name =~ s/\(([^)]*)\)$//s) { $proto = $1; } if (index($name, ':') > 0) { $fq_name = $name; $name = substr($fq_name, 1+rindex($fq_name, ':')); } else { $fq_name = $pkg.'::'.$name; } my $options; if (@_ && ref $_[0]) { $options = shift; splice(@$options, 0, 0, @$common_options) if $common_options; } elsif ($common_options) { # Just duplicate common options $options = [ @$common_options ]; } my $cmd = $name; my $args; my %options; if ($options) { while (@$options) { my $opt = shift @$options; (my $opt_short = $opt) =~ s/^[\$\@\%\&]//; if ($opt eq '--') { _croak 'duplicate @ARGV' if $args && !$common_options; $args = $options; last } elsif ($opt eq '()') { $proto = shift @$options; } elsif ($opt =~ /^\$?0$/s) { # $0 $cmd = shift @$options; } elsif ($opt =~ /^\@?ARGV$/) { # @ARGV _croak "$name: invalid \@ARGV" if ref($options->[0]) ne 'ARRAY'; $args = shift @$options; } elsif (! exists ($OPTIONS{$opt_short})) { _carp "$name: unknown option $opt"; } elsif (defined $OPTIONS{$opt_short}) { my $value = shift @$options; unless (defined $value) { _croak "$name: value expected for option $opt" } elsif (ref($value) ne $OPTIONS{$opt_short}) { _croak "$name: invalid value for option $opt" } $options{$opt_short} = $value; } else { $options{$opt_short} = 1; } } } unless (File::Spec->file_name_is_absolute($cmd)) { my ($vol, $dir, undef) = File::Spec->splitpath($cmd); if (length($vol)+length($dir) == 0) { $cmd = File::Which::which($cmd); } } my $sub = defined($cmd) ? _build_sub($name, [ $cmd, ($args ? @$args : ())], \%options) : sub { _croak "'$name' not found in PATH" }; # As set_prototype *has* a prototype, we have to workaround it # with '&' &Scalar::Util::set_prototype($sub, $proto) if defined $proto; no strict 'refs'; *{$fq_name} = subname $fq_name, $sub; } } sub _handle_error { my ($name, $code, $cmd, $handler) = @_; if ($handler) { $handler->($name, $?, $cmd); } else { _croak "$name error ".($?>>8) } } sub _build_sub { my ($name, $cmd, $options) = @_; return sub { my ($input, $output_cb); $output_cb = pop if ref $_[$#_] eq 'CODE'; $input = pop if ref $_[$#_]; my @cmd = (@$cmd, @_); print join(' ', '[', (map { / / ? qq{"$_"} : $_ } @cmd), ']'), "\n" if DEBUG; my $h; my $out = gensym; # IPC::Run needs GLOBs # errors from IPC::Run must be reported as comming from our # caller, not from here local @IPC::Run::CARP_NOT = (@IPC::Run::CARP_NOT, __PACKAGE__); local %ENV = (%ENV, %{$options->{ENV}}) if exists $options->{ENV}; if ($input) { my $in = gensym; $h = start \@cmd, 'pipe', $out or _croak $!; binmode($in, $options->{'>'}) if exists $options->{'>'}; if (ref $input eq 'ARRAY') { print $in map { "$_$/" } @$input; } elsif (ref $input eq 'SCALAR') { # use ${$input}} as raw input print $in $$input; } close $in; } else { $h = start \@cmd, \undef, '>pipe', $out or _croak $!; } binmode($out, $options->{'<'}) if exists $options->{'<'}; if (wantarray) { my @output; if ($output_cb) { local $_; while (<$out>) { chomp; push @output, $output_cb->($_) } } else { while (my $x = <$out>) { chomp $x; push @output, $x } } close $out; finish $h; _handle_error($name, $?, \@cmd, $options->{'?'}) if $? >> 8; return @output } elsif (defined wantarray) { # Only the first line my $output; defined($output = <$out>) and chomp $output; close $out; finish $h; _handle_error($name, $?, \@cmd, $options->{'?'}) if $? >> 8; _croak "no output" unless defined $output; return $output } else { # void context if ($output_cb) { local $_; while (<$out>) { chomp; $output_cb->($_) } } close $out; finish $h; _handle_error($name, $?, \@cmd, $options->{'?'}) if $? >> 8; return } } } 1; __END__ =encoding utf-8 =head1 NAME System::Sub - Wrap external command with a DWIM sub =head1 VERSION version 0.162800 =head1 SYNOPSIS use System::Sub 'hostname'; # Just an example (use Sys::Hostname instead) # Scalar context : returns the first line of the output, without the # line separator my $hostname = hostname; # List context : returns a list of lines without their line separator use System::Sub 'ls'; my @files = ls '-a'; # Process line by line ls -a => sub { push @files, $_[0]; }; use System::Sub 'df' => [ '@ARGV' => [ '-P' ] ]; # -P for POSIX df => sub { return if $. == 1; # Skip the header line # Show the 6th and 5th columns printf "%s: %s\n", (split / +/, $_[0])[5, 4]; }; # Import with options use System::Sub ssh => [ '$0' => '/usr/bin/ssh', '@ARGV' => [ qw< -o RequestTTY=no > ] ]; # Handle exit codes use System::Sub 'zenity'; # a GTK+ dialog display eval { zenity --question => --text => 'How are you today?' => --ok-label => 'Fine!' => --cancel-label => 'Tired.' }; given ($? >> 8) { when (0) { } when (1) { } } # Import with a prototype (see perlsub) use System::Sub 'hostname()'; # Empty prototype: no args allowed use System::Sub hostname => [ '()' => '' ]; # Alternate syntax use strict; # This will fail at compile time with "Too many arguments" hostname("xx"); =head1 DESCRIPTION See also C> for even simpler usage. C provides in your package a sub that wraps the call to an external program. The return value is line(s) dependending on context (C). This may be what you need if you want to run external commands as easily as from a Unix shell script but with a perl-ish feel (contextual output). So this is not a universal module for running external programs (like L) but instead a simpler interface for a common style of external programs. C may be useful if: =over 4 =item * you want to run the command synchronously (like C or backquotes) =item * the command =over 4 =item - is non-interactive (all the input is fed at start) =item - input is C<@ARGV> and C =item - output is C =item - the exit code is what matters for errors =item - C will not be captured, and will go to C of your program. =back =back The underlying implementation is currently L, but there is no garantee that this will stay that way. L works well enough on both Unix and Win32, but it has its own bugs and is very slow. =head1 IMPORT OPTIONS Options can be set for the sub by passing an ARRAY just after the sub name on the C line. The sigil (C<$>, C<@>, C<%>) is optional. =over 4 =item * C<()>: prototype of the sub. See L. =item * C<$0>: the path to the executable file. It will be expanded from PATH if it doesn't contain a directory separator. =item * C<@ARGV>: command arguments that will be inserted before the arguments given to the sub. This is useful if the command always require a basic set of arguments. =item * C<%ENV>: environment variables to set for the command. =item * C>: I/O layers for the data fed to the command. =item * C>: I/O layers for the data read from the command output. =item * C<&?>: sub that will be called if ($? >> 8) != 0. sub { my $name = shift; # name of the sub my $code = shift; # exit code ($?) my $cmd = shift; # array ref to the executed command # Default implementation: require Carp; Carp::croak("$name error ".($code >> 8)); } Mnemonic: C<&> is the sigil for subs and C<$?> is the exit code of the last command. =back =head1 SUB USAGE =head2 Arguments The scalar arguments of the sub are directly passed as arguments of the command. The queue of the arguments may contain values of the following type (see L): =over 4 =item * C A sub that will be called for each line of the output. The argument is the C-ed line. sub { my ($line) = @_; } This argument must always be the last one. =item * C A reference to a scalar containing the full input of the command. =item * C A reference to an array containing the lines of the input of the command. C<\n> will be appended at the end of each line. =back =head2 Return value(s) =over 4 =item * Scalar context Returns just the first line (based on C<$/>), chomped or undef if no output. =item * List context Returns a list of the lines of the output, based C<$/>. The end-of-line chars (C<$/> are not in the output. =item * Void context If you do not specify a callback, the behavior is currently unspecified (suggestions welcome). =back =head1 SEE ALSO =over 4 =item * L, distributed with Perl 5 to 5.14. Removed from core in 5.16. =item * L, L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =head1 TRIVIA I dreamed about such a facility for a long time. I even worked for two years on a ksh framework that I created from scratch just because at the start of the project I didn't dare to bet on Perl because of the lack of readability of the code when most of the work is running other programs. After that project I never really had the need to run the same command in many places of the code, and in many different ways. Until I had the need to wrap L in the L script of my L project. I wrote the first version of the wrapper there, and quickly extracted it as this module. So, here is it! Last but not least, the L in the package name is intended. =head1 AUTHOR Olivier MenguE, C. =head1 CONTRIBUTORS Philippe Bruhat (L). See the L for details. =head1 COPYRIGHT & LICENSE Copyright E 2012 Olivier MenguE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. =cut # vim:set et sw=4 sts=4: System-Sub-0.162800/README0000644000175000017500000000057212775555647014216 0ustar dolmendolmen This archive contains the distribution System-Sub, version 0.162800: Wrap external command with a DWIM sub This software is copyright (c) 2014 by Olivier Mengué. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.005. System-Sub-0.162800/xt/0000775000175000017500000000000012775555647013767 5ustar dolmendolmenSystem-Sub-0.162800/xt/author/0000775000175000017500000000000012775555647015271 5ustar dolmendolmenSystem-Sub-0.162800/xt/author/pod-syntax.t0000644000175000017500000000025212775555647017561 0ustar dolmendolmen#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); System-Sub-0.162800/xt/author/pod-coverage.t0000644000175000017500000000033412775555647020027 0ustar dolmendolmen#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); System-Sub-0.162800/xt/release/0000775000175000017500000000000012775555647015407 5ustar dolmendolmenSystem-Sub-0.162800/xt/release/kwalitee.t0000644000175000017500000000027512775555647017403 0ustar dolmendolmen# this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.12 use strict; use warnings; use Test::More 0.88; use Test::Kwalitee 1.21 'kwalitee_ok'; kwalitee_ok(); done_testing; System-Sub-0.162800/Changes0000644000175000017500000000173712775555647014635 0ustar dolmendolmenRevision history for System-Sub. 0.162800 2016-10-07 DOLMEN (Olivier Mengué) Fix $_ corruption by wrapper subs (RT#118114 reported by BooK). 0.150960 2015-04-06 DOLMEN (Olivier Mengué) Fix metadata: add back the source repository on GitHub POD: add more SEE ALSO links (Shell, Capture::Tiny) 0.142280 2014-08-16 DOLMEN (Olivier Mengué) Add option '&?' to handle exit code != 0. Add common options (an ARRAY as first import arg) that will apply to all the commands on the import list. Doc: add link to Shell.pm (Thanks Slaven Rezic, RT#84739). 0.130210 2013-01-21 DOLMEN (Olivier Mengué) Add option '()' to define the prototype of the sub. 0.130180 2013-01-18 DOLMEN (Olivier Mengué) Define the DEBUG compile symbol with 'constant.pm'. This fixes Pod::Coverage tests. Minor fixes from BOOK (Philippe Bruhat). 0.123440 2012-12-09 DOLMEN (Olivier Mengué) Initial release, at the Quack and Hack 2012 Europe hackathon. System-Sub-0.162800/LICENSE0000644000175000017500000004366612775555647014356 0ustar dolmendolmenThis software is copyright (c) 2014 by Olivier Mengué. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014 by Olivier Mengué. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by Olivier Mengué. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End System-Sub-0.162800/dist.ini0000644000175000017500000000117012775555647014775 0ustar dolmendolmenname = System-Sub author = Olivier Mengué license = Perl_5 copyright_holder = Olivier Mengué copyright_year = 2014 [@Filter] -bundle = @Basic -remove = ExtraTests [AutoVersion] major = 0 [NextRelease] ;format = %-9v %{yyyy-MM-dd}dT%{HH:mm:ssZ}d %U format = %-9v %{yyyy-MM-dd}d DOLMEN (Olivier Mengué) [PkgVersion] [PodVersion] [MetaJSON] [GithubMeta] remote = github [Prereqs] Scalar::Util = 1.11 ; For set_prototype [AutoPrereqs] [MinimumPerl] [Test::Compile] [PodSyntaxTests] [PodCoverageTests] [Test::Kwalitee] [@Git] push_to = github tag_format = v%v tag_message = CPAN release %v