Subject: | use parent q{Encode::Encoding}; fails: Can't locate object method "Define" via package "Encode::utf8" |
Since this commit (first in 2.90):
commit 55364c9dfa1e3ce611cdff08fc576c86a0bdcdf4
Author: Pali <pali@cpan.org>
Date: Wed May 31 22:35:31 2017 +0200
Remove no warnings 'redefine'; and correctly load dependences
Calling no warnings 'redefine'; just hide a read problem that one function
is later redefined by another. Such thing should not happen, and if there
is it should be fixed.
The real problem is exporting all Encode functions into used modules,
including functions encode() and decode(). Correct way is to export only
those functions which are really needed by modules. Or to call Encode
function with whole package name (e.g. Encode::find_encoding).
Another problem is time when Encode module is loaded. By calling require it
is done at runtime, after current file was already parsed. It is too late
specially for prototyped functions and also constant. Calling use instead
of require fixes this problem.
After those fixes no warnings 'redefine'; can be removed and modules are
warning-free.
Various Encode-related distributions fails to build because Define() method does not exist when loading Encode::Encoding:
$ perl -Iblib/{lib,arch} -e 'package Encode::Foo; use parent q{Encode::Encoding};'
Can't locate object method "Define" via package "Encode::utf8" at blib/lib/Encode.pm line 347.
Compilation failed in require at blib/lib/Encode/Encoding.pm line 11.
BEGIN failed--compilation aborted at blib/lib/Encode/Encoding.pm line 11.
Compilation failed in require at /usr/share/perl5/vendor_perl/parent.pm line 16.
BEGIN failed--compilation aborted at -e line 1.
The test case is a reduced code from Encode::Encoding POD.