in reply to Module name case typo silent failure

It depends on the operating system or resp. file system.

Your code creates a fatal error on Linux but (after adaption°) runs on Windows because the standard FS there is case-insensitive

Linux:

perl -MTime::Hires=time -Wle 'print time' Can't locate Time/Hires.pm in @INC

Windows:

C:\WINDOWS\system32>perl -MTime::Hires=time -Wle "print time" 1568923613

use is a require + import at compile time

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

That is it does a require of Time::HiRes (case-insensitive finds Hires.pm ) but fails to call Time::Hires->import() (Perl is case-sensitive)

Corion already explained that a missing ->import method doesn't create an error, and the typo'ed Module = package = Time::Hires has no ->import routine.

One might argue that the non-existence of the package Time::Hires should raise an error, probably you should file an error with perlbug.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

°) QUESTION: Where did you test that code???

Replies are listed 'Best First'.
Re^2: Module name case typo silent failure
by AnomalousMonk (Archbishop) on Sep 19, 2019 at 20:29 UTC
    ... file an error with perlbug.

    Having a case-preserving but case-insensitive file system is another wonderful feature of Windows. Perl tries to be OS-agnostic, but there's only so much a humble program can do. The fact that this problem has not been addressed so far suggests to me that it's very difficult or impossible to deal with in this particular OS. Can you think of a way?


    Give a man a fish:  <%-{-{-{-<

      > Can you think of a way?

      IMHO the problem is at another place.

      It's OK that ->import() is not required to exist inside a package (or let's say I doubt that this can be changed in a backwards compatible way).

      But trying to call a method on a non-existing package could fail. I.e. use could check if the MODULE-name exists in the right capitalization after require.*

      But for reasons that I do not understand yet does require auto-vivify the misspelled package.

      DB<7> require DaTa::DuMpEr DB<8> x grep {/dumper/i} %DaTa:: 0 'DuMpEr::' 1 *DaTa::DuMpEr:: DB<9>

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      *) or if it exists twice in different capitalizations.

Re^2: Module name case typo silent failure
by LanX (Saint) on Sep 19, 2019 at 20:37 UTC
    > One might argue that the non-existence of the package Time::Hires should raise an error, probably you should file an error with perlbug.

    not sure what is happening there, something creates the wrong namespace %Time::Hires:: after a require

    DB<1> x grep {/hires/i} %Time:: empty array DB<2> require Time::Hires DB<3> x grep {/hires/i} %Time:: 0 'HiRes::' 1 *Time::HiRes:: 2 'Hires::' 3 *Time::Hires:: DB<4>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      The stash is created when parsing the require function. It doesn't even have to be run. This generally doesn't matter but can have an impact on things like indirect method calls.

      Existence of a stash isn't really a useful concept though. Too many things can lead to a stash existing, including loading a sub-package (loading Blurf::Guff would cause the Blurf:: stash to exist).

        > Existence of a stash isn't really a useful concept though.

        I think it's good enough for just another "possible typo" warning.

        Especially if the stash HiRes:: is created after requiring the module Hires which resolved to the file HiRes.pm .

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^2: Module name case typo silent failure
by Anonymous Monk on Sep 19, 2019 at 21:17 UTC
    Where did you test that code???
    
    perl -MConfig -le'print join" ",$],$^O,$Config{osvers}'
    5.028000 darwin 17.5.0
    
    
    Thank you for the thorough explanation.
      > 5.028000 darwin 17.5.0

      your FS must be case-insensitive then (?)

      > Thank you

      Your welcome! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        your FS must be case-insensitive then (?)

        Yes case-insensitive APFS on macOS 10.13.4.