If you donβt want to do anything special in your YAML, you can simply configure the correct coercion for your moose classes, and then pass the loaded data to new() . For instance:
package My::Types; use Moose::Util::TypeConstraints; class_type 'My::Related::Class'; coerce 'My::Related::Class', from 'HashRef', via { My::Related::Class->new(%$_) }; package My::Class; use Moose; has name => (is => 'ro', isa => 'Str'); has related => (is => 'ro', isa => 'My::Related::Class', coerce => 1); package My::Related::Class; use Moose; has flavor => (is => 'ro', isa => 'Str');
Then in some YAML:
name: "An instance of My::Class" related: flavor: "Dangerberry!"
Then in some code:
my $obj = My::Class->new(Load($yaml_data)); print ref $obj->related;
This, of course, is not a whirl, without additional customization of your Moose classes - it's just for building objects. In addition, you need to know which classes are the root objects.
This is probably enough for many simple applications.
source share