A Little more Testing of the waters

Still exploring the MooseX name-space these days and today I was going to have a look at 'MooseX::YAML' as that was the format I was saving my AD&D data in it (for the time being) I thought it might be a good fit to load things up faster or at least save me some code in writing a YAML parse role.

So I started out with a little YAML to test

use MooseX::YAML;

my $dwarf_yaml = <<YAML;
- Fighter:8
dexterity: 15
constitution: 16
charisma: 18
race: 'Dwarf'
name: 'Glarp Gnlnarn'
strength: 18
exceptional: 91

Then I should just be able to load in my YAML and be done.

my $dwarf_yaml = MooseX::YAML::Load($dwarf_yaml);

my $dwarf = MooseX::Blessed::Reconstruct->new->visit($dwarf_yaml);

print $dwarf->name()."\n";
print "charisma=".$dwarf->charisma()."\n";
print "strength=".$dwarf->strength();
print " (".$dwarf->exceptional().")\n"
print "opens a door on a ". $dwarf->open_door_on_a()."\n";
print "opens a barred door on a ".$dwarf->open_barred_doors_on_a()."\n"

But I get this

Can't call method "name" on unblessed reference at clone_it.pl line 28.

Well a little closer examination of the rather sparse POD and I see this

--- !My::Module # this syntax requires YAML::XS

So maybe I need to tell it what Class I am trying to load so I give it a try like this

my $dwarf_yaml = <<YAML;
  --- !RPG::ADD::Character

and now it works

Glarp Gnlnarn
strength=18 (91)
opens a door on a 4

Ok that works, but perhaps they could improve the PDO a little explaining the '--- !' syntax as well as they explained the YAML parser syntax,

So now I can skip the YMAL file loading 'Role' I was working on because this works fine;

my $dwarf = MooseX::YAML::LoadFile('D:/blogs/Glarp_Gnlnarn.yaml');

Great I have saved myself a little typing and now the only problem is now I have to change how I have been saving my characters. Well now that I have this working perhaps it is time to work that part of the code out??


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations