Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Best practices for warnings about wrong context

by dsheroh (Monsignor)
on Oct 05, 2015 at 08:44 UTC ( [id://1143792]=note: print w/replies, xml ) Need Help??


in reply to Best practices for warnings about wrong context

I can't imagine how (b) could be a "yes". Different callbacks are naturally used in different contexts. Sometimes it makes sense for a callback to return a value, other times it doesn't. And sometimes (like Catalyst), the framework is generic enough that the framework designer can't know in advance whether a return value is expected from a given callback or not.

All that aside, I lean towards "no" on (a) regardless. The entire concept of issuing a warning for calling a sub in the wrong context rubs me the wrong way on a rather deep level. I can't identify exactly why, but it's probably connected to the fact that "doing something that doesn't make sense to the module's author" does not necessarily imply "doing something wrong".

  • Comment on Re: Best practices for warnings about wrong context

Replies are listed 'Best First'.
Re^2: Best practices for warnings about wrong context
by mr_mischief (Monsignor) on Oct 05, 2015 at 16:31 UTC

    Maybe I've taken references to a few different subs and passed them around, and then at some point call whichever one has been passed? Maybe some other sub returns a scalar, a hashref, a list, or whatever. What happens if I want to use the sub that refuses to be used in list context or scalar context?

    Well I can wrap it in another sub, maybe an anonymous sub, which doesn't seem like a heart-rending, mind-warping workaround. Should wrapping it be necessary? Who's to say, really? If someone wants to return any kind of user data or status information, it would require the wrapper anyway since the author didn't return anything from the original sub. One might as well have the wrapper call it in void context then return whatever you like.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143792]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found