Iron Moose

Well looks like clean up day again on the old Moose-Pen. Well I hate to say it but 90% of today's post is on types again as my cleanup found a little problem with my 33_conditions.t test case. I know it was running fine yesterday but that changed when I discovered that I had commented out a good hunk of my tests before I though I was finished.

So looking back I did say I no longer needed the from hash-ref on my coerce of ArrayRefofConditions it seems I did not notice that I had commented out the test for a single hash coercion so I added that back in and my test failed. So I had to add in the 'from 'HashRef', via' for my various collection attributes.

Now I also forgot that that I will want users to be able to enter an Array Ref of values on my various dynamic attributes so looking at conditions I would like to do this;

$in_hash = {
conditions=>[{left =>{name =>'last_name2',
view =>'People'},
right =>{value=>'test'},
operator =>'=',
open_parenthes =>1,
condition =>'AND',
{condition =>'AND',
left =>{name=>'first_name3',
right =>{value=>'test'},
operator =>'=',
open_parenthes =>0,

ok($da->add_condition($in_hash->{conditions}),"can add an array Ref of Dynamic conditions");


$dad->conditions,'Array Ref Dynamic condition');

What I had to do was use a little recursion in my sub as the '_$' for this coercion comes out as

$_=[[{condition 1},{condition 1},]];

so a quick change to my '_predicate_array_or_object' sub

if ( ref($object) eq $class ) {
push( @{$objects}, $object );
++ elsif ( ref($object) eq "ARRAY" ) {
++ push( @{$objects},@{_predicate_array_or_object(
++ $class, $object )});
++ }

and all my tests pass even the new ones.

I also had to add the same sort of test to my other dynamic_attributes and on 35_links.t I ran into the same problems so I have to fix up the 'sub _link_array_or_object' function in the same way as the one above. I also had to fix up the 'sub _right_left_coerce' in the same way as well but without the recursion for my 31_elements.t test case.

To get the 35_links.t to work I also had to clean up the 'Test::Database::Accessor::Utils::deep_links' a little to take into account that I have both static and dynamic links.

Now I re-ran most of my tests and the majority passed so I then though it was time I cleaned some little things, I did a perl tidy on most of the files to make them look pretty. Next I then reorganized all the elements of my file so they where all together by class_type, sub_type, coerce and then my custom sub.

Well after all this playing about and I re-ran my test an got all 177 of my collection attributes tests passing.

So I think I am finally done with types.

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