in reply to inconsistent module access

I can get the weird behaviour if I use IO::All without running its import, i.e. using
use IO::All ();

or using require instead of use.

Another way to skip the import is to redefine it:

sub IO::All::import {} use IO::All;

Without seeing the actual code, I'm not sure I can help you more.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: inconsistent module access
by geoffleach (Scribe) on Jun 25, 2022 at 04:17 UTC
    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.

      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.

      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

Re^2: inconsistent module access
by geoffleach (Scribe) on Jun 25, 2022 at 03:28 UTC
    No joy, alas. I would be glad to share the code, but not to clutter up this space. Suggestion?
      I would be glad to share the code, but not to clutter up this space. Suggestion?

      Github is your friend for hosting longer postings that may involve more than one file. Then post the link here. Typically, there's one file that cannot be posted for security reasons, but you can post a mock-up of what it has to look like, and what values have to be supplied in order for it to run. Sometimes the attempt at making it shorter or more self-contained is worth the effort.

        Github is your friend ...

        Online public repositories are useful for sharing open source code. Some, like CPAN, are community owned with all the transparency and common goals that this implies. Others, like GitLab, are owned by independent operators as a gateway service to their core products. Still others, like Github, are owned by monopolistic tech giants out for every last ounce of worth which they might possibly wring from your data/code. Choose wisely.

        Github is not my friend.


        🦛