- Classes are Perl modules.
- Properties are "blessed" into existence.
- Objects are bound to methods or variables via the -> operator.
Object oriented Perl script
#!/usr/bin/perl
use strict;
package cat;
sub new {
my ($class, $hair, $name, $weight) = @_;
bless \$hair, $class;
bless \$name, $class;
bless \$weight, $class;
}
sub hair {
my $self = shift;
return $$self;
}
sub name {
my $self = shift;
return $$self;
}
sub weight {
my $self = shift;
return $$self;
}
sub purr {
my ($self, $volume) = @_;
return $volume * $self->weight;
}
my $cat = cat->new('black', 'Spook', 3.2);
print $cat->purr(3);