First excuse for this complex type of question lacking a minimal non-working example, but the code is really too complex to derive a MWE.
Anyway I’ll try to explain the problem:
Starting from a working system that uses several classes with multiple and repeated inheritance in Perl (mastering that caused the complexity of the code), I wanted to change an “enum” implemented by a set of constants with an Enum
type I had invented.
That Enum
would generate the constants as before, but it would also remember the names as strings, so one could convert names to numbers, and the way back…
In a nutshell this code fragment in Auth::VerifyStatus.pm
would create an enum (the real one is more complex):
use Enum v1.0.0;
use constant _VERIFY_STATI => Enum->new('VS_STAT', [qw(OK ERR_BAD ERR_INVALID)]);
The constants generated would be the concatenation of the base name with the list items, like VS_STAT_OK
, VS_STAT_ERR_BAD
, …
That package would allow export of the constants as well as the enum, similar to this (complexity removed):
%EXPORT_TAGS = (
'enums' => [qw(_VERIFY_STATI)],
'status_enum' => [_VERIFY_STATI->names()],
);
The names
method returns a list of the names generated by the Enum
.
Now I have another package named Auth::Verifier.pm
that does use Auth::VerifyStatus v1.7.0 qw(:status_enum);
and (as it seems to be necessary) does re-export the status constants as well:
%EXPORT_TAGS = (
'enums' => [qw(Auth::VerifyStatus::_VERIFY_STATI)],
'status_enum' =>
[map { 'Auth::VerifyStatus::' . $_ }
Auth::VerifyStatus::_VERIFY_STATI->names()]);
(I added that map
to qualify the package when trying to make it work, because I ran into unexpected problems)
Trying to debug the situation, I arrived nowhere; the only thing I know is that the problem starts after the final 1;
in Auth::Verifier
when running perl -MAuth::Verifier -de1
:
...
Auth::Verifier ONE
Auth::Verifier::CODE(0x2224de0)(lib/Auth/Verifier.pm:261):
261: 1;
DB<1> c
Constant subroutine Auth::VerifyStatus::VS_STAT_OK redefined at -e line 0.
main::BEGIN() called at -e line 0
eval {...} called at -e line 0
Prototype mismatch: sub Auth::VerifyStatus::VS_STAT_OK () vs none at -e line 0.
main::BEGIN() called at -e line 0
eval {...} called at -e line 0
...
(The “ONE” output was added immediately before the 1;
at the end of the package)
The Exporter
is evaluated in a BEGIN
block, also as it seemed to be necessary, like this (also in the other package):
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS, @ISA, $VERSION);
BEGIN {
use Exporter qw(import);
$VERSION = v1.7.0;
$DB::single = 1; # trying to debug this
@ISA = qw(Flags);
%EXPORT_TAGS = (
...
So I’m absolutely clueless how to debug this (too many “line 0”) in a reasonable way, or how to fix this.
Or am I demanding to much from Perl and should use a real OO language instead?