Subject: | Options are global |
Sadly this is probably going to be pretty hard to fix, but basically your options are global to the interpreter. That's fine when Data::Printer is exclusively used by the developer for ad-hoc debugging, but if, for instance, you wanted to use Data::Printer to format error messages in a log, the options set there are applied everywhere. To be clear, this code fails:
perl -E'package A; use Data::Printer alias => "_dump";' -E'package main; use Data::Printer; my $x = {}; p $x'
FWIW I think the best solution would be to do something similar to what we did in Log::Contextual, where under the hood there is an object with the options applied. The object could, in this case, probably be stored in a hash where the key is the package that did the importing. Then "package Foo; use Data::Printer coloring => 0" becomes sugar for: "$printer_for_package{Foo} = Data::Printer::Object->new( coloring => 0 );" and p just proxies to that object.
If I get a chance I may factor out the object as that would be sufficient for my use case.