Honestly, I am not sure how valuable knowledge of Perl's raw OO primitives is for writing new code anymore. I have not used @ISA or "use base" or "bless" in my code for a very long time; any OO I do is via the Moose MOP. (I do rebless instances, of course, but I use $meta->rebless_instance instead of just "bless". Much cleaner!)
Anyway, I would teach yourself Moose first. It is easy to get started and get productive right away, and you can pick up the details as you become more proficient in Perl and programming in general.
As an example:
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10'; # for 'say'
use MooseX::Declare;
class Point {
has [qw/x y/] => ( is => 'ro', isa => 'Num', required => 1 );
method new_from_ordered_pair(ClassName $class: Num $x, Num $y){
return $class->new( x => $x, y => $y );
}
method distance(Point $a: Point $b){
return sqrt( ($a->x - $b->x)**2 + ($a->y - $b->y)**2 );
}
}
my $origin = Point->new_from_ordered_pair(0,0);
my $point = Point->new_from_ordered_pair(3,4);
say '(3,4) is '. $point->distance($origin). ' units away from the origin.';
Notice how there is no more fighting with the details of Perl's implementation. You can easily worry about the details of your program instead of how to do OO in Perl. You don't even have to make a "Point.pm" file, you can have the class definition inline.
I also think this code would be immediately understandable to almost any programmer -- even ones not familiar with the details of Perl or Moose (or MooseX::Declare).
(BTW, this example worked out a bit oddly with the ":" syntax in the method signatures. Normally, you get an instance of yourself called $self as the first arg. If you supply something else before a : in the signature, you can change the type and name of the variable. I also wrote "new_from_ordered_pair" so that you wouldn't have to type x => $x, y => $y
as the arguments to new every time. This is just sugar that I think is nice; nothing magical is happening here.)
Finally, you get a lot here "for free". Try these, and note the helpful error messages:
Point->new; # x is required
Point->new_from_ordered_pair('foo', 'bar'); # x needs to be a number
$point->distance('some string'); # $b needs to be a Point
You get all this for free, and it makes debugging your program easier. There is no reason to avoid it, it really makes programming more enjoyable (and it makes your program more reliable... for free!)
Oh, one more thing. With Moose, you can introspect your classes. This might not be important right away, but it can be nice to have. Open Devel::REPL, type 'do "test.pl"' to load the Point class, and then say something like:
map { $_->name } Point->meta->get_all_attributes;
The result is ['x', 'y']
. Without having the source code, you can find out what attributes the class has. Try doing that with "plain" Perl OO. (This sort of thing is what makes the rich MooseX:: namespace possible. You might not need introspection, but you will enjoy the ability to use reliable modules from CPAN.)