A small bit of explanation to supplement what is above:
X->new(...) (with the arrow) does two things:
- It causes X to be passed as an implicit parameter, as if you had called new('X',...). Because no class was being passed into new, the routine to create an object bless($someref, $someclass) was called with $someclass set to undef as its class parameter. This causes Perl to bless the object into 'main': hence the cryptic messages about main not containing a definition for the method. - see bless.
- It causes Perl to search the class and superclass definitions for a definition of new(...) This can come in handy when you want to add some methods to an existing class, but are happy with the way the existing class constructs objects.
As for learning about Perl objects: the information is spread across multiple documents, perltoot provides a better overview of how Perl handles key OOP concepts. perlobj is more of a discussion of how the Perl language implements objects, e.g. "A class is just a package...". In addition:
- perlboot provides an Perl oriented introduction to the whole idea of OOP.
- perltooc provides some options for managing class level data
- perlbot provides some ways to get creative with objects: Perl has a very flexible approach - just about anything can be turned into an object: references to scalars, references to hashes, references to arrays, and even references to subroutines!
Best, beth