Don't complicate the code, just make more methods. In OO they are cheap to add. (
Re: OO design: returning string and/or special value (peephole Object) preempted me.)
I don't like the suggestion from Re: OO design: returning string and/or special value, flags are a code smell.
use Moops;
use Data::Dx;
class Special;
class Foo {
method _actual_work { return 'foo', Special->new }
method my_method(--> Any) { return $self->_actual_work }
method my_method_special(--> InstanceOf['Special']) { return ($sel
+f->_actual_work)[1] }
method my_method_string(--> Str) { ($self->_actual_work)[0] }
}
my $f = Foo->new;
Dx $f->my_method;
Dx $f->my_method_special;
Dx $f->my_method_string;
I also experimented with
multi-methods, but unfortunately Perl is too irregular to allow dispatch on return types.
PS: Curate GET