[tbb-commits] [Git][tpo/applications/rbm][main] Bug 40072: Move capture_exec to a separate module

boklm (@boklm) git at gitlab.torproject.org
Fri Feb 9 09:08:09 UTC 2024



boklm pushed to branch main at The Tor Project / Applications / RBM


Commits:
efd874ab by Nicolas Vigier at 2024-02-08T13:13:58+01:00
Bug 40072: Move capture_exec to a separate module

Because the RBM and RBM::DefaultConfig modules have circular dependencies,
exporting functions from RBM to RBM::DefaultConfig doesn't work, which
means that part of the changes for rbm#40068 didn't work. We could fix
that by using `RBM::capture_exec` instead of `capture_exec`. An other
solution is to make a separate module for `capture_exec`. Since the RBM
modules is becoming big, I think it's a good idea to move independent
parts to a separate modules.

- - - - -


3 changed files:

- lib/RBM.pm
- + lib/RBM/CaptureExec.pm
- lib/RBM/DefaultConfig.pm


Changes:

=====================================
lib/RBM.pm
=====================================
@@ -10,7 +10,6 @@ use YAML::XS qw(LoadFile);
 use Template;
 use File::Basename;
 use IO::Handle;
-use Capture::Tiny qw(capture);
 use File::Temp;
 use File::Copy;
 use File::Copy::Recursive qw(fcopy);
@@ -18,6 +17,7 @@ use File::Path qw(make_path);
 use File::Basename;
 use String::ShellQuote;
 use Sort::Versions;
+use RBM::CaptureExec qw(capture_exec);
 use RBM::DefaultConfig;
 use Digest::SHA qw(sha256_hex);
 use Data::UUID;
@@ -29,7 +29,7 @@ use feature "state";
 BEGIN {
     require Exporter;
     our @ISA = qw(Exporter);
-    our @EXPORT = qw(exit_error capture_exec);
+    our @EXPORT = qw(exit_error);
 }
 
 our $config;
@@ -308,15 +308,6 @@ sub exit_error {
     exit (exists $_[1] ? $_[1] : 1);
 }
 
-sub capture_exec {
-    my @cmd = @_;
-    my ($stdout, $stderr, $exit) = capture {
-        system(@cmd);
-    };
-    return ($stdout, $stderr, $exit == 0, $exit) if wantarray();
-    return $stdout;
-}
-
 sub set_git_gpg_wrapper {
     my ($project) = @_;
     my $w = project_config($project, 'gpg_wrapper');


=====================================
lib/RBM/CaptureExec.pm
=====================================
@@ -0,0 +1,21 @@
+package RBM::CaptureExec;
+
+use Capture::Tiny qw(capture);
+
+BEGIN {
+    require Exporter;
+    our @ISA = qw(Exporter);
+    our @EXPORT = qw(capture_exec);
+    our @EXPORT_OK = qw(capture_exec);
+}
+
+sub capture_exec {
+    my @cmd = @_;
+    my ($stdout, $stderr, $exit) = capture {
+        system(@cmd);
+    };
+    return ($stdout, $stderr, $exit == 0, $exit) if wantarray();
+    return $stdout;
+}
+
+1;


=====================================
lib/RBM/DefaultConfig.pm
=====================================
@@ -10,7 +10,8 @@ BEGIN {
 }
 
 use File::Basename;
-use RBM qw(capture_exec);
+use RBM;
+use RBM::CaptureExec qw(capture_exec);
 use Cwd qw(getcwd);
 use File::Temp;
 use File::Path qw(make_path);



View it on GitLab: https://gitlab.torproject.org/tpo/applications/rbm/-/commit/efd874abee2d4afe652feb6c79c1d929f70d136b

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/rbm/-/commit/efd874abee2d4afe652feb6c79c1d929f70d136b
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240209/46fa6c08/attachment-0001.htm>


More information about the tbb-commits mailing list