in reply to Re: converting from switch to given-when
in thread converting from switch to given-when
PS: if there's any possibility that $selection could potentially contain an arrayref, then my solution might behave a little oddly; you could explicitly protect against arrayrefs:
sub is_arrayref (_) { ref(shift) eq 'ARRAY' } given ($selection) { when (is_arrayref) { die "unexpected!" } when ([wxID_YES]) { $self->Wx::LogStatus('You pressed: "Yes"' ) + } when ([wxID_NO]) { $self->Wx::LogStatus('You pressed: "No"' ) + } when ([wxID_CANCEL]) { $self->Wx::LogStatus('You pressed: "Cancel"') + } }
Of course, probably the code that generates $selection can never generate an arrayref, so you don't need to protect against that possibility.
|
|---|