-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.pl
73 lines (46 loc) · 1.36 KB
/
example.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use strict;
use warnings;
use Data::Class;
class CatFood {
has pounds = 0;
has brand = 'SWEET-TREATZ';
private ratings: arrayref[int] = sub { [] };
set pounds ($self, $amount){
die "Cannot have negative food" if $amount < 0;
$self->pounds = $amount;
}
def feed_lion ($self, $amount: int = 1){
$self->pounds -= $amount;
$self->record_review({rating=>5, taste=>'Delicious'});
}
private def record_review($self, $review: {rating: int, tasting_notes: str}) {
push $self->ratings->@*, $review->{rating};
}
}
my $food = CatFood->new(pounds=>10);
$food->feed_lion();
class BankAccount {
protected balance : int = 0;
set balance( $self, $value : int ) {
die "Account overdrawn!" if $value < 0;
$self->balance = $value;
}
def deposit ( $self, $amount : int ) {
$self->balance += $amount;
}
def withdraw ( $self, $amount: int ) {
$self->balance -= $amount;
}
def check_balance ($self) : int{
return $self->balance;
}
}
class CheckingAccount extends BankAccount {
def atm_withdrawal($self, $amount){
$self->balance -= ($amount + 2);
}
}
my $account1 = BankAccount->new( balance => 100 );
my $account = CheckingAccount->new( balance => 100 );
$account->atm_withdrawal(10);
print $account->check_balance;