my $auto = new car("Opel Vectra",50000);
####
my $auto = car->new("Opel Vectra",50000);
####
use strict;
use warnings;
package Garage;
sub new {
my $pkg = shift;
my $self = {
all_cars => {}, # store cars key'd by license plate (uuid)
}
blese $self, $pkg;
return $self;
}
sub add_car {
my ($self, $car) = $@;
#... add car key'ed by license plate or uuid
}
sub del_car {
my ($self, $uuid) = $@
delete $self->get_cars->{$uuid};
}
sub get_cars {
my $self = shift;
return $self->{all_cars};
}
sub get_car {
my ($self, $uuid) = $@;
my $cars = $self->get_cars;
die "Car with plate $uuid is not in the garage!\n\n" if not $cars->{$uuid}; # die can throw a reference also, so there you can do the exception thing in the caller
return $cars->{$uuid};
}
sub count_cars {
my $self = shift;
my $cars_ref = $self->get_cars;
my $count = @{keys %$cars_ref};
return $count;
}
# add other "collective" methods
1;