in reply to Re^2: Finding out whether a module contains a certain package
in thread Finding out whether a module contains a certain package

Considering that one can have a file Abc.pm
sub Abc::foo { ... } sub Abc::bar { ... }
without any package statement, or even:
BEGIN { my $package = ... Complicated expression ...; eval <<"EOT" package ${package}; sub foo { ... } sub bar { ... } EOT }
I think you can forget about catching all possible cases.

Considering that the majority of the people will write package Abc; near the top of the file, and all you seem to want is earlier program termination, why not perform a check that will catch the majority of the error, and let the few cases where 1) the author doesn't use "package Abc", and 2) the author miscapitalizes the package name, and 3) the author uses a case insensitive file system die sometime later (due to missing subroutines)?

Replies are listed 'Best First'.
Re^4: Finding out whether a module contains a certain package
by rovf (Priest) on May 04, 2009 at 14:38 UTC
    I think you can forget about catching all possible cases. Considering that the majority of the people will write package Abc; near the top of the file, and all you seem to want is earlier program termination,...

    Actually, I don't want to terminate earlier; I want to throw an exception (which will be handled by our central exception handler) and continue with the next task (which hopefully will go well); the problem with the MixinFactory was that it did not terminate with an exception, but terminate ungracefully.

    But this is a minor issue. Basically, I agree with you; and especially since we have control about how the "good" files look like, I will follow your advice and, instead of respecting all pathological cases, require that a good mixin module has to have a package declaration of a certain form near the top of the file; and I will reject everything modules which don't match this pattern.

    -- 
    Ronald Fischer <ynnor@mm.st>