Proc::Easier - run processes with OO goodness
# run a command
# run command and assign resultant Proc::Easier object to a scalar
my $cmd = cmd('ls');
# get info about the object
say $cmd.exit; # exitcode
# dump info about the command for debugging
# run a command, say its output
# run a command, say its error
# run a command from a different directory
# run a command, die if error encountered, then print info
# make :die the default for all commands until its turned off
cmd('kjkjsdkjf'); # this dies
# turn off :die until its turned back on
cmd('kjkjsdkjf'); # this doesn't die
# create a command with standard OO, don't run it immediately
my $cmd= Proc::Easier.new(cmd => 'ls', :lazy);
# run the command
Proc::Easier is a convenient wrapper for the
run command using a OO interface to make issuing commands from Raku much easier.
sub cmd ( Str $cmd, Bool :$dir = '', Bool :$die = False, Bool :$lazy = False )
cmd('ls', '/some/dir', :die);
Convenience method for constructing a
Proc::Easier object. Accepts a command, an optional directory command to run the command from, an an option to die if an error is encountered, and an optoin to make the command "lazy." Lazy commands will not be executed unless the run method is called on the object. Otherwise, oonce the object is constructed, the command will be immediately executed.
multi sub autodie(Bool :$off)
multi sub autodie(Bool :$on)
Turns on/off the autodie switch. All subsequent
Proc::Easier commands will behave as if the
:die feature has been turned on or off. Default is off.
method new( Str:D :$cmd, Str :$dir = '', Bool :$die = False, Bool :$lazy )
Accepts the same four named variables as the
cmd convenience method.
Runs the command.
Returns the string from stdout, if any.
Returns the string from stderr, if any.
Returns the exit code from the shell, '0' indicates success, other numbers indicate an error.
Returns the name of the file where the call was made.
Returns the line number of the file where the call was made.
has Str $.cmd is rw;
Contains the original command.
has Str $.dir is rw;
The directory where the command will be execute.
has Bool $.die is rw;
Whether the command will die if an error is encountered.
Steve Dondley email@example.com
Thanks to tbrowder for the
Proc::Easy distribution which shamelessly inspired the name of this module and furnished some code and ideas to recycle, too.
COPYRIGHT AND LICENSE
Copyright 2022 Steve Dondley
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.