AnyEvent-Git-Wrapper

 view release on metacpan or  search on metacpan

lib/AnyEvent/Git/Wrapper.pm  view on Meta::CPAN

   {
     ...
   }
 });

Like L<Git::Wrapper>, you can also access the standard output and error via the C<OUT> and C<ERR>, but care
needs to be taken that you either save the values immediately if other commands are being run at the same
time.

 $git->branch(sub {
   my $out = $git->OUT;
   foreach my $line (@$out)
   {
     ...
   }
 });

If git signals an error condition the condition variable will croak, so you will need to wrap your call
to C<recv> in an eval if you want to handle it:

 $git->branch(sub {
   my $out = eval { shift->recv };
   if($@)
   {
     warn "error: $@";
     return;
   }
   ...
 });

=head1 CONSTRUCTOR

=head2 new

 my $git = AnyEvent::Git::Wrapper->new('.');

The constructor takes all the same arguments as L<Git::Wrapper>, in addition to 
these options:

=over 4

=item cache_version

The first time the C<version> command is executed the value will be cached so
that C<git version> doesn't need to be executed again (via the C<version> method
only, this doesn't include if you call C<git version> using the C<RUN> method).
The default is false (no cache).

=back

=head1 METHODS

=head2 RUN

Run the given git command with the given arguments (see L<Git::Wrapper>).  If the last argument is
either a code reference or a condition variable then the command will be run in non-blocking mode
and a condition variable will be returned immediately.  Otherwise the command will be run in 
normal blocking mode, exactly like L<Git::Wrapper>.

If you provide this method with a condition variable it will use that to send the results of the
command.  If you provide a code reference it will create its own condition variable and attach
the code reference  to its callback.  Either way it will return the condition variable.

 # blocking
 $git->RUN($command, @arguments);
 
 # non-blocking callback
 $git->RUN($command, @arguments, sub {
   # $out is a list ref of stdout
   # $err is a list ref of stderr
   my($out, $err) = shift->recv;
 });
 
 # non-blocking cv
 my $cv = $git->RUN($command, @arguments, AE::cv);
 $cv->cb(sub {
   my($out, $err) = shift->recv;
 });

=head2 status

If called in blocking mode (without a code reference or condition variable as the last argument),
this method works exactly as with L<Git::Wrapper>.  If run in non blocking mode, the L<Git::Wrapper::Statuses>
object will be passed back via the C<recv> method on the condition variable.

 # blocking
 # $statuses isa Git::Wrapper::Statuses
 my $statuses = $git->status;

 # with a code ref
 $git->status(sub {
   # $statuses isa Git::Wrapper::Statuses 
   my $statuses = shift->recv;
   ...
 });
 
 # with a condition variable
 my $cv = $git->status(AE::cv)
 $cv->cb(sub {
   # $statuses isa Git::Wrapper::Statuses
   my $statuses = shift->recv;
   ...   
 });

=head2 log

This method has three different calling modes, blocking, non-blocking as commits arrive and non-blocking
processed at completion.

=over 4

=item blocking mode

 $git->log(@args);

Works exactly like L<Git::Wrapper>

=item as commits arrive

 # without a condition variable
 $git->log(@args, sub {



( run in 0.962 second using v1.01-cache-2.11-cpan-e1769b4cff6 )