The pattern that I most commonly see for this type of 'workflow' internal to a module (not across module boundries) is to use _
to prefix a private variable.
class foo (
$mandatory_param,
$optional_param = undef,
){
# either using a selector to set a 'default' value, usually used if I am munging multiple params, or if one potential default value depends on a different param (like paths relative to a base path)
$_optional_param = $optional_param ? {
undef => 'none',
default => $optional_param,
}
}
Or more generally, just use a default. value, and conditionally assign a different parameter to use in a different location that 'requires' undef.
class bar (
$mandatory_param,
# Or just use a default value explicitly
$optional_param = 'none',
){
#...
}
PP is not a procedural language. All “variables” have a final value with their first assignment. Also you're comparing against the string 'undef'. You want to check against the literal undef (not surrounded by single quotes).
I made only example what I need.. there is no any way to make condition like this?