Entering MooseX, Part the Fith

Well just a sort one tonight as other moose-poop-21534987.jpg got in the way,

I did talk in my last post yesterday about adding a little enhancement to my first little MooseX and after talking with some of my co-conspirators they though it would be useful that the requirements are as follows

Have at least one the indicated roles
Have all the indicated roles
Have a mix of 'Required' and at least one indicated role

So how to add that in??

Well the it does not look very hard rather than pass just a simple array to the sub why not pass a hash that has the data classified for me. On can do this in a number of ways by adding here are a few'

A hash with the keys as the roles and the values indicating it is required or not

 
{

Product::BRULE::Standing_Offer=>'Required',
Product::BRULE::PO=>'required',
Product::BRULE::COD=>'Optional'
}

which of course gives us the potential problem of more bugs as a simple typo now on the hash value (I made one on Product::BRULE::PO) will cause this to skip this role as required. We could add in a bunch of data validation code and or code that will ignore the case but that would mean more code and I am lazy.

I could try

 
{   
    Product::BRULE::Standing_Offer=>1,
    Product::BRULE::PO=>1,
    Product::BRULE::COD=>0,
}

Now the problem is I am passing Majick number into my code saying Hocus Pocus and raising the ire of most of the programmers on CPAN and perhaps having some of them turn in their graves so that is out.

Now taking a step forward and thinking what would be easiest for me as the programmer and what is the most easily understood I should really do it this way

 
{
requires=>['Product::BRULE::Standing_Offer', 'Product::BRULE::PO'],
one_of=>['Product::BRULE::COD']
}
So now my API is easy to understand and my coding for this will be a little easier as I simply process two keys. I still have the problem of data validation hey but I only have to check it once per call unlike the first example where I would have to check for each key in the hash. The world is full of compromises and I can live with this

Now to just code it up

IMG_1847.jpg

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