NAME

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

DESCRIPTION

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

You can curry objects is what I mean.

PROPERTIES

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.

config

The config from the mgconfig file for this repo.

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

METHODS

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 %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 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 run accepts.

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

data

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

stdout - The STDOUT from the operation. Will be set to the empty string if undef.
stderr - The STDERR from the operation. Will be set to the empty string if undef.
exitcode - The $? equivalent as produced by IO::Async::Process.
past_stdout - The STDOUT from the prior command
past_stderr - The STDERR from the prior command

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

IO::Async::Process

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

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

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

gather(%data)

Intended for currying. This goes between runs and ensures output is not lost.

Concatenates the STDOUT and STDERR from the command with the respective STDOUT or STDERR of the previous command and continues the chain.

$repo->run([qw/git command/])
    ->then($repo->curry::run([qw/another git command/]))
    ->then($repo->curry::gather)
    ->then(App::Multigit::report($repo))

See run for the shape of the data

report(%data)

Intended for currying, and accepts a hash-shaped list à la run.

Returns a Future that yields a two-element list of the directory - from the config - and the STDOUT from the command, indented with tabs.

Use gather to collect STDOUT/STDERR from previous commands too.

The yielded list is intended for use as a hash constructor.

my $future = App::Multigit::each(sub {
    my $repo = shift;
    $repo->run([qw/git command/])
        ->then($repo->curry::run([qw/another git command/]))
        ->then($repo->curry::gather)
        ->then($repo->curry::report)
    ;
});

my %report = $future->get;

for my $dir (sort keys %report) { ... }

_indent

Returns a copy of the first argument indented by the number of tabs in the second argument. Not really a method on this class but it's here if you want it.

AUTHOR

Alastair McGowan-Douglas, <altreus at perl.org>

BUGS

Please report bugs on the github repository https://github.com/Altreus/App-Multigit.

LICENSE

Copyright 2015 Alastair McGowan-Douglas.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0