| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Multigit::Future; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 5 | use base qw( IO::Async::Future ); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 866 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.16'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 NAME | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | App::Multigit::Future - Futures for App::Multigit | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | Extensio of IO::Async::Future with a few extra methods. | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 METHODS | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head2 finally | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | Like C, but unpacks the Future and calls C on the result. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | As documented in L, all | 
| 25 |  |  |  |  |  |  | operations complete with the same data structure. This is also true when a | 
| 26 |  |  |  |  |  |  | command fails to run. | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | This is therefore a convenience method that runs the subref with the C<%data> | 
| 29 |  |  |  |  |  |  | structure, irrespective of whether the preceding steps caused a failure or not. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | my $final_f = mg_each(sub { | 
| 32 |  |  |  |  |  |  | my $repo = shift; | 
| 33 |  |  |  |  |  |  | $repo->run([qw/ git command that might fail /]) | 
| 34 |  |  |  |  |  |  | ->finally($repo->curry::report); | 
| 35 |  |  |  |  |  |  | }); | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =cut | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub finally { | 
| 40 | 0 |  |  | 0 | 1 |  | my ($self, $code) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | $self->followed_by( sub { | 
| 43 | 0 |  |  | 0 |  |  | my $f = shift; | 
| 44 | 0 |  |  |  |  |  | my @result; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 | 0 |  |  |  |  | if (@result = $f->failure) { | 
| 48 | 0 |  |  |  |  |  | @result = @result[2 .. $#result]; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | else { | 
| 51 | 0 |  |  |  |  |  | @result = $f->get; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 |  |  |  |  |  | (ref $f)->done(@result); | 
| 55 |  |  |  |  |  |  | }) | 
| 56 | 0 |  |  |  |  |  | ->then($code); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; |