Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible scalar/list context problems in proxy methods #53

Open
preaction opened this issue Dec 13, 2016 · 0 comments
Open

Fix possible scalar/list context problems in proxy methods #53

preaction opened this issue Dec 13, 2016 · 0 comments

Comments

@preaction
Copy link
Owner

preaction commented Dec 13, 2016

Right now, the default Log::Any::Proxy tries to return the formatted message so that the user can use that to send a warn or die with an exception. The proxy also has boolean methods for determining if the given log level is currently activated (like is_warn and is_debug). But there are a few cases where the proxy uses a bare return, which can cause problems if the user is expecting a scalar (either a log message, or a boolean).

This may be contrived, but if the user does something like this:

my %data = (
    foo => $LOG->infof( $got_foo ),
    bar => $LOG->infof( $got_bar ),
);

and both $got_foo and $got_bar are undefined, then %data will end up being foo => "bar", which is absolutely not what the user expected.

Then if the user also uses $LOG->is_debug to see if the app is in debug mode, they will end up with an odd number of elements in their hash when it is not in debug mode.

In theory this means enforcing booleanness on https://metacpan.org/source/PREACTION/Log-Any-1.045/lib/Log/Any/Proxy.pm#L75 to isolate the user from problems in the adapter, and returning undef at the two bare returns in this method: https://metacpan.org/source/PREACTION/Log-Any-1.045/lib/Log/Any/Proxy.pm#L92-97

All of these methods should return a scalar explicitly. This is an API change (hooray), so we'll have to warn people we're doing it.

Repository owner deleted a comment from vshekun Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant