Help for this page

Select Code to Download


  1. 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 }
    }
    
  2. 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) }
    }
    
  3. 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);