Git::Class::Cmd
use strict; use warnings; use Git::Class; my $git = Git::Class::Cmd->new; my $worktree = $git->clone('git://github.com/charsbar/git-class.git'); my $captured = $git->status; # as a whole my @captured = $git->status; # split by "\n" # other interface, mainly for internal use my $cmd = Git::Class::Cmd->new( die_on_error => 1, verbose => 1 ); $cmd->git( commit => { message => 'a commit message', all => '' } );
This is a simple wrapper of a git executable. The strength is that you can run a git command and capture the output in a simple and more portable way than using open to pipe (which is not always implemented fully).
git
open
As of this writing, most of the git commands (methods of this class) simply returns the output, but this will be changed in the near future, especially when called in the list context, where we may want sort of proccessed data like what files are affected etc.
Most of the git commands are implemented as a role. See Git::Class::Role::* for details.
returns true if the git command exists (or specified explicitly).
takes a git command name (whatever git executable recognizes; it doesn't matter if it's implemented in this package (as a method/role) or not), and options/arguments for that.
Options may be in a hash reference (or hash references if you prefer). You don't need to care about the order and shell-quoting, and you don't need to prepend '--' to the key in this case, but you do need to set its value to a blank string("") (or undef) if the option doesn't take a value. Of course you can pass option strings merged in the argument list.
""
undef
Note that if you want to pass options for git executable (instead of git command options), pass them as a hash reference first, before you pass a command string, and command parameters.
$cmd->git({ git_dir => '/path/to/repo/' }, 'command', ...);
Returns a captured text in the scalar context, or split lines in the list context. If some error (or warnings?) might occur, you can see it in $object->_error.
$object->_error
Note that if the $object->is_verbose, the captured output is printed as well. This may help if you want to issue interactive commands.
$object->is_verbose
If you want to trace commands, set GIT_CLASS_TRACE environmental variable to true.
GIT_CLASS_TRACE
is an accessor/mutator to determine if we should use Capture::Tiny to capture the output of git commands. If your web apps hang because of the capturing, set this to true to disable it.
Kenichi Ishigaki, <ishigaki@cpan.org>
Copyright (C) 2009 by Kenichi Ishigaki.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Git::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Class
CPAN shell
perl -MCPAN -e shell install Git::Class
For more information on module installation, please visit the detailed CPAN module installation guide.