This was fun. Calls to $self->_initialize exposed a nasty bug. There's enough context below for you to see it.
sub _initialize {
my $self = shift;
$self->SUPER::_initialize;
my $description = $self->{description};
$self->{$_} = [] foreach $self->_can_contain;
while ( my ( $type, $class ) = each %{ $self->_item_classes } ) {
my $source = $self->source;
foreach my $metadata ( @{ $description->{$type} } ) {
push @{ $self->{$type} } =>
$class->new_from_metadata( {
metadata => $metadata,
source => $source,
} );
}
}
}
sub _item_classes {
my $self = shift;
my %class_for = (
attributes => 'Bermuda::Island::Attribute',
elements => 'Bermuda::Island::Element',
);
my %item_classes;
foreach my $type ( $self->_can_contain ) {
$item_classes{$type} = $class_for{$type};
}
return \%item_classes;
}
sub _can_contain { qw/ attributes elements / }
Wow. People usually spot it sooner than this. Looks like I had a bit of stumper on this one. Good work