package Local::MrRepo::Repo; # Copyright (C) 2019-2020 Sean Whitton # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use strict; use warnings; use Exporter 'import'; use File::Spec::Functions qw(rel2abs); use Local::Interactive qw(system_pty_capture); use List::Util qw(all); # Quoting perldoc perlmodlib: "As a general rule, if the module is # trying to be object oriented then export nothing. If it's just a # collection of functions then @EXPORT_OK anything but use @EXPORT # with caution." our @EXPORT_OK = (); # constructor sub new { my ($class, $toplevel) = @_; bless {toplevel => rel2abs($toplevel), updated => 0} => $class; } # attributes sub toplevel { shift->{toplevel} } sub updated { shift->{updated} } # public methods sub auto_commit { shift->_mr_cmd("-m", "autoci") } sub update { my $self = shift; # note that this may also stow my $result = $self->_mr_cmd("update"); $self->{updated} = 1 if $result->{exit} == 0 # permit nonzero exit for package that might still be in NEW || $result->{output} =~ /^dgit: source package [a-z0-9+.-]+ does not exist in suite [a-z]+\s*$/m; return $result; } sub status { my $self = shift; my $result = $self->_mr_cmd("status"); # in the case of command success with zero output, get rid of mr's # own output, so caller can just check for an empty string if ($result->{exit} == 0) { my @output = grep /[[:print:]]/, split "\n", $result->{output}; $result->{output} = "" if all { /^mr status: / } @output; } return $result; } # private methods sub _mr_cmd { # here we interpolate @_ into a string because # Local::Interactive::_sysptycap_script cannot handle a list of # arguments (though Local::Interactive::_sysptycap_tty can) system_pty_capture("mr -d " . shift->toplevel . " @_"); } 1;