App-Multigit

 view release on metacpan or  search on metacpan

lib/App/Multigit/Repo.pm  view on Meta::CPAN

use 5.014;

our $VERSION = '0.18';

=encoding utf8

=head1 NAME

App::Multigit::Repo - Moo class to represent a repo

=head1 DESCRIPTION

Holds the name and config for a repo, to make future chaining code cleaner.

You can curry objects is what I mean.

=head1 PROPERTIES

=head2 name

Name as in the key from the mgconfig file that defines this repo. As in, the
URL.

It's called name because it doesn't have to be the URL, but is by default.

=cut

has name => (
    is => 'ro',
);

=head2 config

The config from the mgconfig file for this repo.

This is given a C<dir> key if the config does not already specify one.

=cut

has config => (
    is => 'ro',
);

=head1 METHODS

=head2 run($command, [%data])

Run a command, in one of two ways:

If the command is a CODE ref, it is run with this Repo object, and the entirety
of C<%data>. The CODE reference should use normal print/say/warn/die behaviour.
Its return value is discarded. If the subref returns at all, it is considered to
have succeeded.

If it is an ARRAY ref, it is run with IO::Async::Process, with C<stdout> sent
to the process's STDIN.

A Future object is returned. When the command finishes, the Future is completed
with a hash-shaped list identical to the one C<run> accepts.

If an error occurs I<before> running the command (i.e. if IO::Async throws the
error), it will behave as though an error occurred within the command, and
C<exitcode> will be set to 255.

=head3 data

C<run> accepts a hash of data. If C<stdout> or C<stderr> are provided here, the
Future will have these values in C<past_stdout> and C<past_stderr>, and
C<stdout> and C<stderr> will get populated with the I<new> STDOUT and STDERR
from the provided C<$command>.

=over

=item C<stdout> - The STDOUT from the operation. Will be set to the empty string
if undef.

=item C<stderr> - The STDERR from the operation. Will be set to the empty string
if undef.

=item C<exitcode> - The C<$?> equivalent as produced by IO::Async::Process.

=item C<past_stdout> - The STDOUT from the prior command

=item C<past_stderr> - The STDERR from the prior command

=back

C<past_stdout> and C<past_stderr> are never used; they are provided for you to
write any procedure you may require to concatenate new output with old. See
C<gather>.

=head3 IO::Async::Process

The special key C<ia_config> to the C<%data> hash will be removed from the hash
and used as configuration for the L<IO::Async::Process> object that powers the
whole system.

It currently supports the C<no_cd> option, to prevent attempting to C<chdir>
into the repo's directory.

  $repo->run($subref, ia_config => { no_cd => 1 });

=cut

sub run {
    my ($self, $command, %data) = @_;
    my $future = loop->new_future;

    bless $future, 'App::Multigit::Future';

    $data{stdout} //= '';
    my $ia_config = delete $data{ia_config};

    my $ignore_stdout = $App::Multigit::BEHAVIOUR{ignore_stdout};
    my $ignore_stderr = $App::Multigit::BEHAVIOUR{ignore_stderr};

    my $finish_code = sub {
        my (undef, $exitcode, $stdout, $stderr) = @_;
        my %details = (
            stdout => $ignore_stdout ? '' : $stdout,
            stderr => $ignore_stderr ? '' : $stderr,



( run in 1.006 second using v1.01-cache-2.11-cpan-39bf76dae61 )