Perl-Toolchain-Gang / Module-Metadata

Gather package and POD information from perl module files
http://metacpan.org/release/Module-Metadata/
Other
8 stars 16 forks source link

Guard against accidental failures if Log::Contextual is loaded. #14

Closed kentfredric closed 9 years ago

kentfredric commented 9 years ago

If by chance Module::Metadata happened to be loaded in a system where Log::Contextual was loaded, but not configured, Module::Metadata calling the relevant logging methods caused a fatal exception.

This change permits Module::Metadata to construct its own logger if it plans on using Log::Contexual, such that if one is not configured, the default will still work.

Additionally, the default logger can be adjusted in the user ENV by tweaking MODULEMETADATA<> fields when Log::Contexual is loaded.

Its unlikely a user will stumble into this edge case, as it only happens in error conditions, and then, only in a rarely used codepath in Module::Metadata.

Namely:

  log_info -
    <- $compare_versions
      <- $resolve_module_versions
        <- package_versions_from_directory(&1)
      <- package_versions_from_directory(&1)
    <- package_versions_from_directory=&1
      <- provides

Of these methods, only package_versions_from_directory has a single test, and that single test doesn't trip the error conditions.

karenetheridge commented 9 years ago

I wonder if we should just take this Log::Contextual bit out. It seems to have been there since before the module was split off from Module::Build, and doesn't really make sense in a core module. e.g. none of the other core modules have special treatment for LC loggers.

@shadowcat-mst can you provide some history?

karenetheridge commented 9 years ago

I see nothing wrong with the patch though, so let's merge it :)