package Widget; use strict; use warnings; require Carp; require Widget::Part; sub new { my $class = shift; $class = ref($class) || $class; my $self = { parts => { }, }; bless $self, $class; return $self; } sub addPart { my $self = shift; my %opts = (@_); # Create the new part: my $part; unless ( $part = Widget::Part->new(%opts) ) { Carp::carp("unable to add Widget part"); return undef; } $self->{parts}{$opts{type}} = $part; return $part; # use as bool or ref to part object. } 1;