Perl::...ptions(3pm)
π NAME π
okay so bestie, this page is all about Perl::Critic::Policy::Community::OverloadOptions β and what it does is it tells you: don't use overload without specifying a bool overload and enabling fallback. that's the whole vibe check. periodt. β¨
(this lives in the Perl::...ptions(3pm) manual, User Contributed Perl Documentation, iykyk π«Ά)
π¦ DESCRIPTION π¦
so the overload module lets an object class say how an object should behave when it's used in all kinds of operations. cute, right? but here's the thing β the moment you activate it, it turns on extra behavior by default:
- it autogenerates overload behavior for operators you didn't specify π
- and if it can't autogenerate an overload for some operator, using that operator on the object will throw an exception π
an autogenerated boolean overload can lead to surprising behavior, where an object gets considered "false" because of some other overloaded value. like, for example: say a class overloads stringification to return the object's name, but the object's name is 0. then the object will be considered false, because of an autogenerated overload that uses the boolean value of the string. π«
that is rarely the behavior you want, ngl. and if you do need it, you can just set it as an explicit bool overload. easy.
and then β without setting the fallback option, any operators that can't be autogenerated from your defined overloads will result in an exception when used. by setting fallback to 1, the operator will instead fall back to standard behavior, as if no overload was defined at all. which is, like, generally the expected behavior when you're only overloading a few operations. β¨
use overload '""' => sub { $_[0]->name }; # not ok
use overload '""' => sub { $_[0]->name }, bool => sub { 1 }; # not ok
use overload '""' => sub { $_[0]->name }, fallback => 1; # not ok
use overload '""' => sub { $_[0]->name }, bool => sub { 1 }, fallback => 1; # ok
look at that last one. that's the one. that's the main character. π
πΈ AFFILIATION πΈ
this policy is part of Perl::Critic::Community. found family fr fr π«Ά
π CONFIGURATION π
this policy is not configurable except for the standard options. that's it, that's the tea. no extra knobs, no little dials, nothing. π
π AUTHOR π
Dan Book, dbook@cpan.org β thank you for your service, legend π
π COPYRIGHT AND LICENSE π
Copyright 2015, Dan Book.
This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.
β SEE ALSO β
Perl::Critic
and that's the whole page bestie π written up against perl v5.40.1, dated 2025-03-22 β go forth and set your fallback, mwah π
β¨
π¦ where this page comes from
- debian trixie: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu resolute: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu stonking: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms