-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop.pl
53 lines (47 loc) · 1.02 KB
/
oop.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
package Product;
use strict;
use warnings;
# init product with serial, name and price
sub new{
my ($class,$args) = @_;
my $self = bless { serial => $args->{serial},
name => $args->{name},
price => $args->{price}
}, $class;
}
# get name of the product
sub get_name{
my $self = shift;
return $self->{name};
}
# set new name for the product
sub set_name{
my ($self,$new_name) = @_;
$self->{name} = $new_name;
}
# get price of the product
sub get_price{
my $self = shift;
return $self->{price};
}
# set price for the product
sub set_price{
my ($self,$new_price) = @_;
$self->{price} = $new_price;
}
# get serial
sub get_serial{
my $self = shift;
return $self->{serial};
}
# set serial
sub set_serial{
my ($self,$new_price) = @_;
$self->{price} = $new_price;
}
# return formatted string of the product
sub to_string{
my $self = shift;
return "Serial: $self->{serial}\nName: $self->{name}\nPrice: $self->{price}USD\n";
}
1;