in reply to Using perl 6 roles in perl 5

Roles would be one way to solve this, but I think there are better ways.

I have an Object base class which is inherited by other objects eg User, Group, Image. When each of these is loaded, they register their Type with the Object class so that any object can be retrieved using the parent class and blessed into the right package.

I am not sure if this is the right approach. In OO, the Class is traditionally the element which "manages instances", not the Object. However, Perl 5's OO model being what it is, the distinction between class and object are very blurry. But either way, this is all irrelvant since I assume you are not looking to create a domain specific object metamodel to solve you problem.

I would suggest that you instead use the Factory pattern here, which is not all that different from what you are doing, except you are calling your factory "Object". Then within your Factory you can handle all the constraints (singleton or not singleton) and relations (all classes are associated with a group) between your objects as just "configuration" within the factory. This approach would easily fufill all your stated requirements.

-stvn

Replies are listed 'Best First'.
Re^2: Using perl 6 roles in perl 5
by clinton (Priest) on Jan 18, 2006 at 15:32 UTC
    You're absolutely right - that is what I'm doing. My only experience of OO is through Perl, so forgive me if my terminology is shaky.

    When I said When each of these is loaded, they register their Type with the Object class so that any object can be retrieved using the parent class and blessed into the right package., I really meant that each sub class registers with the parent class, which I have called Object.

    And which is, as you say, a factory class. It handles the auto-generated accessor methods, the required attribute checking when saving an object, loading, caching and saving objects etc.