sub all{ my $self = shift; my $method = shift; foreach my $t ( values %{$_attributes{triangles}}) { $method->($t); } } #then call with $g->all(\&Triangle::flatten);