action #104670
closedFix circular dependency of autotest <-> bmwqemu
Description
Motivation¶
See https://github.com/os-autoinst/os-autoinst/pull/1905 which fixes the circular dep bmwqemu -> backend::driver -> myjsonrpc -> bmwqemu
autotest
uses bmwqemu
. bmwqemu
uses $autotest::current_test
in one of its functions and does a require autotest
for this.
Correct solution would be to move $autotest::current_test
to its own module, that both bmwqemu
and autotest
can use.
Problem: Backwards compatibility
Subtasks
Updated by tinita almost 3 years ago
One solution could be a tied scalar (using ()
parens to visualize the tied value):
% cat currenttest.pm
package currenttest;
use strict;
use warnings;
use experimental 'signatures';
use base 'Tie::Scalar';
use base 'Exporter';
our @EXPORT_OK = qw(current_test set_current_test);
my $current_test;
sub set_current_test ($value) { $current_test = "($value)" }
sub current_test () { $current_test }
sub TIESCALAR ($class, $value) {
set_current_test($value);
return bless {}, $class;
}
sub FETCH ($self) { current_test() }
sub STORE ($self, $value) { set_current_test($value) }
1;
% cat tiedscalar.pl
package main;
use 5.010;
use strict;
use warnings;
use currenttest qw(current_test set_current_test);
tie my $s, 'currenttest', "foo";
say $s;
$s = 23;
say $s;
set_current_test("method call");
say $s;
my $new = $s;
$new = "new";
say $new;
% perl -I. tiedscalar.pl
(foo)
(23)
(method call)
new
This way the old $autotest::current_test
variable could stay where it is for old code that uses it, but it would be tied to the new variable in currenttest.pm
, which we could also use in our internal code.
Updated by tinita almost 3 years ago
- Status changed from New to Resolved
- Assignee set to tinita
- Target version changed from future to Ready
This has actually been fixed by https://github.com/os-autoinst/os-autoinst/pull/1905
Updated by tinita over 2 years ago
- Is duplicate of action #78240: prevent circular dependencies in bmwqemu.pm and autotest.pm to be able to use "strictures" added