in reply to Re: Re: use Module and case-insensitive file names
in thread use Module and case-insensitive file names

Ok. I've changed my strategy:
if ( running_under_windows and Foo.pm loaded and package_Foo doesn't exist ) { warn about case of Foo }
The reason that
use Strict; $x = 10;
is valid is because use is merely:
BEGIN { require Strict; Strict->import; }
And on Windows, require Strict goes through fine, thanks to the caseless OS. And import silently fails (as is documented).

The DaTA::Dumper thing didn't give an error because you didn't turn on warnings. If warnings were on, you'd have seen:

Name "main::Dumper" used only once: possible typo at -e line 1. Filehandle main::Dumper never opened at -e line 1.

_____________________________________________________
Jeff japhy Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Re: Re: use Module and case-insensitive file names
by John M. Dlugosz (Monsignor) on Jul 31, 2001 at 01:03 UTC
    Importing a non-existent package calls Universal::import rather than giving an error? Why do we want that behavior?

    It seems to me that something like you propose used to exist! I recall getting an error when the package didn't match the name. Maybe this was in there before, or still is but doesn't work anymore?

    If you warn that package_Foo doesn't exist after reading Foo.pm, that's a general warning that's good anywhere: the file may have been renamed, you might have fat-fingered the package line when writing it, it might be a symlink, etc. If you are going to make it windows-only, check that some package does exist that's a case mismatch, rather than the target just not existing. To make it complete, need a no warnings 'package_load' as well.

    —John

      If you don't supply an import method for a package, it fails silently without warning. This goes for packages that... well... don't exist at all.

      Here's my code. I hope you understand most of it:

      #ifdef WIN32 if (strcmp(name + len - 3, ".pm")) { char *pkg; int slash_count = 0, i = 0; for (i = 0; i < len - 3; i++) { if (name[i] == '/') slash_count++; } /* "Foo/Bar.pm" + 1 (slash) - 3 (".pm") + 1 ("\0") */ pkg = malloc(sizeof(char) * (len + slash_count - 3 + 1)); slash_count = 0; for (i = 0; i < len - 3; i++) { if (name[i] == '/') { pkg[i + slash_count] = ':'; pkg[i + ++slash_count] = ':'; } else pkg[i + slash_count] = name[i]; } pkg[i + slash_count] = '\0'; if (!gv_stashpv(pkg, FALSE)) Perl_warner(aTHX_ WARN_MISC, "Package %s not found (did yo +u use the incorrect case?)", pkg); } #endif

      _____________________________________________________
      Jeff japhy Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        If you don't supply an import method for a package, it fails silently without warning. This goes for packages that... well... don't exist at all.

        They're two separate issues. Given Foo->bar(), when Foo exists but Foo::bar doesn't, it goes though Autoload, ISA, etc. all the way up to UNIVERSAL. There is a &UNIVERSAL::import, though tye thinks it's a bug.

        But what if Foo doesn't exist? Shouldn't that be a different kind of error? It surely would run into problems when it tried to use &Foo::AUTOLOAD, @Foo::ISA, etc., so I can only suppose that this is intentional behavior!

        —John

        The value of name coming in, that's a relative file name that will be searched for on the @INC list?

        if (strcmp(name + len - 3, ".pm")) { Should be _stricmp, since it might be ".PM" etc.

        Also, what if the name's length is less than three?

        sizeof char is 1, by definition.

        This will warn any time a .pm file doesn't define a package with the same name, so its applicability is not just Win32 case differences. It can be more generally useful, as I mused in another message.

        —John