action #104670
closed
Fix circular dependency of autotest <-> bmwqemu
Added by tinita almost 3 years ago.
Updated over 2 years ago.
Category:
Regressions/Crashes
Estimated time:
(Total: 0.00 h)
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
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.
- Description updated (diff)
- Status changed from New to Resolved
- Assignee set to tinita
- Target version changed from future to Ready
- Is duplicate of action #78240: prevent circular dependencies in bmwqemu.pm and autotest.pm to be able to use "strictures" added
Also available in: Atom
PDF