+{
+ package App::Codeowners::Util::Process;
+
+ sub new {
+ my $class = shift;
+ return bless {@_}, $class;
+ }
+
+ sub next {
+ my $self = shift;
+ my $line = readline($self->{fh});
+ if (defined $line) {
+ chomp $line;
+ if (my $filter = $self->{filter}) {
+ local $_ = $line;
+ $line = $filter->($line);
+ }
+ }
+ $line;
+ }
+
+ sub all {
+ my $self = shift;
+ chomp(my @lines = readline($self->{fh}));
+ if (my $filter = $self->{filter}) {
+ $_ = $filter->($_) for @lines;
+ }
+ \@lines;
+ }
+
+ sub wait {
+ my $self = shift;
+ my $pid = $self->{pid} or return;
+ if (my $fh = $self->{fh}) {
+ close($fh);
+ delete $self->{fh};
+ }
+ waitpid($pid, 0);
+ my $status = $?;
+ print STDERR "# -> status $status\n" if $ENV{GIT_CODEOWNERS_DEBUG};
+ delete $self->{pid};
+ return $status;
+ }
+
+ sub DESTROY {
+ my ($self, $global_destruction) = @_;
+ return if $global_destruction;
+ $self->wait;
+ }
+}
+