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

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:??;

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: use Module and case-insensitive file names
by John M. Dlugosz (Monsignor) on Jul 31, 2001 at 01:59 UTC
    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

      It's not illegal to see if a function exists in a certain package, and it's not illegal to see if an array exists, no matter how you qualify it. There's no bug there. Maybe having UNIVERSAL::import is a bug.

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

        That's what tye points out in the snippet he pointed out on another thread: Exporter::import is aliased into UNIVERSAL::import, so its triggered even if you don't mention Exporter in your module. That just doesn't seem right.
Re: Re: Re: Re: Re: Re: use Module and case-insensitive file names
by John M. Dlugosz (Monsignor) on Jul 31, 2001 at 02:13 UTC
    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

      Ok, I'll add that 3-character check, and the use of strcasecmp().

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