|
NAMEGit::Repository::Command - Command objects for running gitSYNOPSISuse Git::Repository::Command; # invoke an external git command, and return an object $cmd = Git::Repository::Command->new(@cmd); # a Git::Repository object can provide more context $cmd = Git::Repository::Command->new( $r, @cmd ); # options can be passed as a hashref $cmd = Git::Repository::Command->new( $r, @cmd, \%option ); # $cmd is basically a hash, with keys / accessors $cmd->stdin(); # filehandle to the process' stdin (write) $cmd->stdout(); # filehandle to the process' stdout (read) $cmd->stderr(); # filehandle to the process' stdout (read) $cmd->pid(); # pid of the child process # done! $cmd->close(); # exit information $cmd->exit(); # exit status $cmd->signal(); # signal $cmd->core(); # core dumped? (boolean) # cut to the chase my ( $pid, $in, $out, $err ) = Git::Repository::Command->spawn(@cmd); DESCRIPTIONGit::Repository::Command is a class that actually launches a git commands, allowing to interact with it through its "STDIN", "STDOUT" and "STDERR".This class is a subclass of System::Command, meant to be invoked through Git::Repository. METHODSAs a subclass of System::Command, Git::Repository::Command supports the following methods:newGit::Repository::Command->new( @cmd ); Runs a git command with the parameters in @cmd. If @cmd contains a Git::Repository object, it is used to provide context to the git command. If @cmd contains one or more hash reference, they are taken as option hashes. The recognized keys are:
If the Git::Repository object has its own option hash, it will be used to provide default values that can be overridden by the actual option hash passed to "new()". If several option hashes are passed to "new()", they will all be merged, keys in later hashes taking precedence over keys in earlier hashes. The Git::Repository::Command object returned by "new()" has a number of attributes defined (see below). close$cmd->close(); Close all pipes to the child process, and collects exit status, etc. and defines a number of attributes (see below). final_output$cmd->final_output( @callbacks ); Collect all the output, and terminate the command. Returns the output as a string in scalar context, or as a list of lines in list context. Also accepts a hashref of options. Lines are automatically "chomp"ed. If @callbacks is provided, the code references will be applied successively to each line of output. The line being processed is in $_, but the coderef must still return the result string. If the Git command printed anything on stderr, it will be printed as warnings. If the git sub-process exited with a status code listed in the "fatal" option, it will "die()". The defaults fatal exit codes are 128 (fatal error), and 129 (usage message). AccessorsThe attributes of a Git::Repository::Command object are also accessible through a number of accessors.The object returned by "new()" will have the following attributes defined:
Regarding the handles to the child git process, note that in the following code: my $fh = Git::Repository::Command->new( @cmd )->stdout; $fh is opened and points to the output of the git subcommand, while the anonymous Git::Repository::Command object has been destroyed. After the call to "close()", the following attributes will be defined:
AUTHORPhilippe Bruhat (BooK) <book@cpan.org>ACKNOWLEDGEMENTSThe core of Git::Repository::Command has been moved into its own distribution: System::Command. Proper Win32 support is now delegated to that module.Before that, the Win32 implementation owed a lot to two people. First, Olivier Raginel (BABAR), who provided me with a test platform with Git and Strawberry Perl installed, which I could use at any time. Many thanks go also to Chris Williams (BINGOS) for pointing me towards perlmonks posts by ikegami that contained crucial elements to a working MSWin32 implementation. In the end, it was Christian Walder (MITHALDU) who helped me finalize Win32 support for System::Command through a quick round of edit (on my Linux box) and testing (on his Windows box) during the Perl QA Hackathon 2013 in Lancaster. COPYRIGHTCopyright 2010-2016 Philippe Bruhat (BooK), all rights reserved.LICENSEThis program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |