Suggestions how to avoid "Useless use of private variable in void context" ?

11 views
Skip to first unread message

Edward Baudrez

unread,
Nov 16, 2020, 8:08:03 AM11/16/20
to Mojolicious
Hello list

There is this hint in the FAQ about keeping a strong reference to the transaction object $tx around, so that the message "Transaction already destroyed" does not appear in the logs:


However, that yields a warning, viz. "Useless use of private variable in void context" at the lone "$tx". Any hints how to avoid this warning?


Kind regards
Edward

Felipe Gasper

unread,
Nov 16, 2020, 8:41:41 AM11/16/20
to mojol...@googlegroups.com
I think you could do:

$tx = $tx;

… instead. (It might be worth updating the FAQ to do that?)

-F
> --
> You received this message because you are subscribed to the Google Groups "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/8b3ab4a2-5f18-4d1f-8743-82b573af26bbn%40googlegroups.com.

Dan Book

unread,
Nov 16, 2020, 12:18:27 PM11/16/20
to mojol...@googlegroups.com
A common idiom is `undef $tx;` since you are also done with the object at that point.

-Dan

Dan Book

unread,
Nov 16, 2020, 12:18:57 PM11/16/20
to mojol...@googlegroups.com
That is, after the ->reply->exception.

-Dan
Reply all
Reply to author
Forward
0 new messages