in reply to Re: inconsistent module access
in thread inconsistent module access

Hmmm seems like I can cut down the test a tad :-) File t.pl ...
use feature 'switch'; no warnings 'experimental'; $m = 'test'; given ( $m ) { when ('test') { test::Get() }; } package test; sub Get { require IO::All; $data = io(); } 1;
% perl t.pl Undefined subroutine &test::io called at t.pl line 11.
FWIW, changing the call to io()
$data = IO::All::io()
Results in a different error.
Can't call method "_package" on an undefined value at /usr/share/perl5 +/vendor_perl/IO/All.pm line 63.

Replies are listed 'Best First'.
Re^3: inconsistent module access
by haukex (Archbishop) on Jun 25, 2022 at 06:28 UTC

    It's what choroba said: because you're using require instead of use, the module's import method is not called, which is required for the module to work correctly.

    $data = IO::All::io() Results in a different error.

    That's because there is no sub io anywhere in the distribution. io is dynamically generated by the aforementioned import in the caller's package. The unusual error comes from the fact that the call gets sent to IO::All::AUTOLOAD(), which doesn't handle io.

    You need to say either use IO::All; or require IO::All; IO::All->import(); for the module to work correctly.

Re^3: inconsistent module access (require vs use)
by LanX (Saint) on Jun 25, 2022 at 10:18 UTC
    My most esteemed brethren choroba and HaukeX already nailed down your problem.

    But you seem to be confused about the difference between use and require

    from the docs

      use Module

      Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

      BEGIN { require Module; Module->import( LIST ); }

      except that Module must be a bareword. ...

    BEGIN happens at compile-time, if you want to use a module at run-time, you always need to call

    ->import

    too.

    It's also an FAQ, plz see

    --> What's-the-difference-between-require-and-use?

    and plz follow the various links embedded in this node to round up the picture.°

    HTH! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) well you could already have followed some of them before