Dwim loading of moose objects from yaml
# given some class: package My::Module; use Moose; has package => ( is => "ro", init_arg => "name", ); has version => ( is => "rw", init_arg => undef, ); sub BUILD { shift->version(3) } # load an object like so: use MooseX::YAML qw(Load -xs); my $obj = Load(<<'YAML'); --- !My::Module # this syntax requires YAML::XS name: "MooseX::YAML" YAML $obj->package; # "MooseX::YAML" $obj->version; # 3, BUILD was called
This module provides \s-1DWIM\s0 loading of Moose based objects from \s-1YAML\s0 documents.
Any hashes blessed into a Moose class will be replaced with a properly constructed instance (respecting init args, \*(C`BUILDALL\*(C', and the meta instance type).
This is similar to YAML::Active in that certain nodes in the loaded \s-1YAML\s0 documented are treated specially.
All exports are setup by Sub::Exporter using currying.
\*(C`-xs\*(C', \*(C`-syck\*(C' or \*(C`-pp\*(C' can be specified to specify \s-1YAML::XS\s0, YAML::Syck or \s-1YAML\s0 on a per import basis.
If no driver is explicitly chosen \s-1YAML::XS\s0 will be tried first, falling back to \s-1YAML\s0.
This module is maintained using Darcs. You can get the latest version from <http://nothingmuch.woobling.org/code>, and use \*(C`darcs send\*(C' to commit changes.
Yuval Kogman <[email protected]>
Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.