shift @_ if(ref($_[0])); # skip the first argument if it is an object, so it works both as a method and a subroutine
my ($branch_name_or_code, $no_default) = @_;
return ($no_default ? undef : 1) unless(defined($branch_name_or_code));
my $branch_code = ($branch_name_or_code=~/^\-?\d+$/)
? $branch_name_or_code
: {
'MAIN' => 1,
'ANYFAILURE' => 0,
'MEMLIMIT' => -1,
'RUNLIMIT' => -2,
}->{$branch_name_or_code};
return defined($branch_code) ? $branch_code : die "Could not map the branch_name '$branch_name_or_code' to the internal code";
}