A Moose at the Door

imagestyw.jpg
Well I must say MooseX has helped me out again today, You might remember way back to the very first post of this AD&D series I mentioned that I would need all sorts of flavors for the values of my Character Abilities, ie tombstone, present values, magically enhanced values etc.

Well as I was programming along and setting up some playing parts of the game I was continually having to make calls back to the persistence layer (if you can call a YAML file that) for the starting value of an attribute for the current gaming session.

Then while playing with MAP of CPAN(you can tell I really like that site) I found what I think is a solution to this little problem MooseX::BuildArgs

This nifty little gem keeps your build arguments around for you in case you need them.
All I need to do is this


package RPG::ADD::Character;
use Moose;
use MooseX::BuildArgs;

and then I can get all my build arguments as a simple hash ref


my $chacter = RPG::ADD::Character->new({race=>'Dwarf',strength=>9,
	dexterity=>17,
	constitution=>12,
	charisma=>9,
	intelligence=>8,
	wisdom=>9,
	});


print $chacter->build_args->{dexterity};

Well I just started playing about with effect of spells which sometimes effect a character's ability rolls. As good one is the 2nd level MU spell 'Strength', which when cast on a character they get a boost in strength for a short period of time.

Now rather then having to go back to my persistence layer to display the original strength value or adding in yet another attribute I just refer back to the build_arg hash to get the original.

A nice little tool in my bag of Moose tricks

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