.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Git::Repository::Command 3pm" .TH Git::Repository::Command 3pm "2011-12-28" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Git::Repository::Command \- Command objects for running git .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use 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, \e%option ); \& \& # $cmd is basically a hash, with keys / accessors \& $cmd\->stdin(); # filehandle to the process\*(Aq stdin (write) \& $cmd\->stdout(); # filehandle to the process\*(Aq stdout (read) \& $cmd\->stderr(); # filehandle to the process\*(Aq 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); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Git::Repository::Command\*(C'\fR is a class that actually launches a \fBgit\fR commands, allowing to interact with it through its \f(CW\*(C`STDIN\*(C'\fR, \f(CW\*(C`STDOUT\*(C'\fR and \f(CW\*(C`STDERR\*(C'\fR. .PP This class is a subclass of \f(CW\*(C`System::Command\*(C'\fR, meant to be invoked through \f(CW\*(C`Git::Repository\*(C'\fR. .SH "METHODS" .IX Header "METHODS" As a subclass of \f(CW\*(C`System::Command\*(C'\fR, \&\f(CW\*(C`Git::Repository::Command\*(C'\fR supports the following methods: .ie n .SS "new( @cmd )" .el .SS "new( \f(CW@cmd\fP )" .IX Subsection "new( @cmd )" Runs a \fBgit\fR command with the parameters in \f(CW@cmd\fR. .PP If \f(CW@cmd\fR contains a \f(CW\*(C`Git::Repository\*(C'\fR object, it is used to provide context to the \fBgit\fR command. .PP If \f(CW@cmd\fR contains one or more hash reference, they are taken as \&\fIoption\fR hashes. The recognized keys are: .ie n .IP """git""" 4 .el .IP "\f(CWgit\fR" 4 .IX Item "git" The actual git binary to run. By default, it is just \f(CW\*(C`git\*(C'\fR. .Sp In case the \f(CW\*(C`git\*(C'\fR to be run is actually a command with parameters (e.g. when using \fBsudo\fR or another command executer), the option value should be an array reference with the command and parameters, like this: .Sp .Vb 1 \& { git => [qw( sudo \-u nobody git )] } .Ve .ie n .IP """cwd""" 4 .el .IP "\f(CWcwd\fR" 4 .IX Item "cwd" The \fIcurrent working directory\fR in which the git command will be run. .ie n .IP """env""" 4 .el .IP "\f(CWenv\fR" 4 .IX Item "env" A hashref containing key / values to add to the git command environment. .ie n .IP """input""" 4 .el .IP "\f(CWinput\fR" 4 .IX Item "input" A string that is send to the git command standard input, which is then closed. .Sp Using the empty string as \f(CW\*(C`input\*(C'\fR will close the git command standard input without writing to it. .Sp Using \f(CW\*(C`undef\*(C'\fR as \f(CW\*(C`input\*(C'\fR will not do anything. This behaviour provides a way to modify options inherited from \f(CW\*(C`new()\*(C'\fR or a hash populated by some other part of the program. .Sp On some systems, some git commands may close standard input on startup, which will cause a \s-1SIGPIPE\s0 when trying to write to it. This will raise an exception. .PP If the \f(CW\*(C`Git::Repository\*(C'\fR 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 \f(CW\*(C`new()\*(C'\fR. .PP If several option hashes are passed to \f(CW\*(C`new()\*(C'\fR, they will all be merged, keys in later hashes taking precedence over keys in earlier hashes. .PP The \f(CW\*(C`Git::Repository::Command\*(C'\fR object returned by \f(CW\*(C`new()\*(C'\fR has a number of attributes defined (see below). .SS "\fIclose()\fP" .IX Subsection "close()" Close all pipes to the child process, and collects exit status, etc. and defines a number of attributes (see below). .SS "\fIfinal_output()\fP" .IX Subsection "final_output()" Collect all the output, and terminate the command. .PP Returns the output as a string in scalar context, or as a list of lines in list context. Also accepts a hashref of options. .PP Lines are automatically \f(CW\*(C`chomp\*(C'\fRed. .PP If the Git command printed anything on stderr, it will be printed as warnings. If the git sub-process exited with status \f(CW128\fR (fatal error), or \f(CW129\fR (usage message), it will \f(CW\*(C`die()\*(C'\fR. .SS "Accessors" .IX Subsection "Accessors" The attributes of a \f(CW\*(C`Git::Repository::Command\*(C'\fR object are also accessible through a number of accessors. .PP The object returned by \f(CW\*(C`new()\*(C'\fR will have the following attributes defined: .IP "\fIcmdline()\fR" 4 .IX Item "cmdline()" Return the command-line actually executed, as a list of strings. .IP "\fIpid()\fR" 4 .IX Item "pid()" The \s-1PID\s0 of the underlying \fBgit\fR command. .IP "\fIstdin()\fR" 4 .IX Item "stdin()" A filehandle opened in write mode to the child process' standard input. .IP "\fIstdout()\fR" 4 .IX Item "stdout()" A filehandle opened in read mode to the child process' standard output. .IP "\fIstderr()\fR" 4 .IX Item "stderr()" A filehandle opened in read mode to the child process' standard error output. .PP Regarding the handles to the child git process, note that in the following code: .PP .Vb 1 \& my $fh = Git::Repository::Command\->new( @cmd )\->stdout; .Ve .PP \&\f(CW$fh\fR is opened and points to the output of the git subcommand, while the anonymous \f(CW\*(C`Git::Repository::Command\*(C'\fR object has been destroyed. Once \f(CW$fh\fR is destroyed, the subprocess will be reaped, thus avoiding zombies. .PP After the call to \f(CW\*(C`close()\*(C'\fR, the following attributes will be defined: .IP "\fIexit()\fR" 4 .IX Item "exit()" The exit status of the underlying \fBgit\fR command. .IP "\fIcore()\fR" 4 .IX Item "core()" A boolean value indicating if the command dumped core. .IP "\fIsignal()\fR" 4 .IX Item "signal()" The signal, if any, that killed the command. .SH "AUTHOR" .IX Header "AUTHOR" Philippe Bruhat (BooK), \f(CW\*(C`\*(C'\fR .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" The core of \f(CW\*(C`Git::Repository::Command\*(C'\fR has been moved into its own distribution: \f(CW\*(C`System::Command\*(C'\fR. Proper Win32 support is now delegated to that module. .PP Before that, the Win32 implementation owed a lot to two people. First, Olivier Raginel (\s-1BABAR\s0), 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 (\s-1BINGOS\s0) for pointing me towards perlmonks posts by ikegami that contained crucial elements to a working MSWin32 implementation. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2010\-2011 Philippe Bruhat (BooK), all rights reserved. .SH "LICENSE" .IX Header "LICENSE" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.