- or download this
given ($payment_method) { # All code samples are Perl 6
when 'credit' { do_credit_card($num, $exp) }
when 'debit' { do_debit_card($num, $exp) }
when 'check' { do_check() }
default { die }
}
- or download this
class MyStore::PayMethod {
# A submethod is a method that isn't inherited.
submethod new { die "Create a subclass, silly." }
...
method execute($price) { (code to execute) }
method store($dbh) { (code to store) }
}
- or download this
my $class;
given($payment_method) {
when 'credit' { $class=MyStore::PayMethod::CreditCard }
...
when 'check' { $class=MyStore::PayMethod::Check }
}
my $payobj=$class.new(*%params);