#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package MyApp::Object; use Moose; has greeting => (isa => 'Str', is => 'ro', required => 1); sub collection { ref(shift) . '::Collection' } { my %collection; sub BUILD { my ($self) = @_; my $class = $self->collection; Moose::Meta::Class->create( $class, methods => { push => sub { push @{ $collection{ +shift } }, $self }, greet => sub { say $_->greeting for @{ $collection{ +shift } } }, }, ); $class->push($self); } } __PACKAGE__->meta->make_immutable; } { package MyApp::ChildObject; use Moose; extends 'MyApp::Object'; __PACKAGE__->meta->make_immutable; } my $o = 'MyApp::Object'->new(greeting => 'Hallo'); $o->collection->greet; my $c1 = 'MyApp::ChildObject'->new(greeting => 'Ciao'); my $c2 = 'MyApp::ChildObject'->new(greeting => 'Salut'); $c1->collection->greet;