Moose Loose Ends Part the Third

Its pull hair day here in the Moose-Pen

Yesterday I merrily finished off all the changes where I swapped out die for confess and the changes where I updated the error messages to the same standard. I then happily check in Accessor.pm and was looking forward to a quick testing post for today. happily finished and checked the lot in. Then tried to run my test suite an got;


t/00_load.t ................. 1/1
# Failed test 'use Database::Accessor;'
# at t/00_load.t line 7.
# Tried to use 'Database::Accessor'.
# Error: syntax error at /home/scolesj/database-accessor/lib/Database/Accessor.pm line 627, near "if"
# syntax error at /home/scolesj/database-accessor/lib/Database/Accessor.pm line 718, near "if"

opps obviously I did not run any tests before I checked in and pushed my code to github.

The problem finding this bug with the where it was telling me the bug was 'line 627' great but it was blank as was 718??

Well at least I knew that the error was around the code I was playing with yesterday and that would have been my new 'confess' statements. After a few mins review those I still could not track down the bug.

Finally I had to use githug to look at a what I had checked in and then I at least go a clue to the bug.


– die "Attempt to $action without condition"
++ confess("Database::Accessor $action Error: Attempt to $action without a condition!"

and there it was I added in a '(' but forgot to close it. The funny thing well frustrating really was the missing ')' was on line '680' way below '627'. I guess that is just perl matching up brackets and dieing when if fails on it.

There where 3 other places I made this mistake and it took me a goo 30 minutes to get things back into order. Oh well at least I get paid by the hour.

After all of that I did get this on the test suite run


t/50_create.t ............... 1/9 Database::Accessor create( $db 'Class', $container 'Hash-Ref||Class||Array-Ref of [Hash-ref||Class]', $options 'Hash-Ref'); Error: Incorrect Usage: The $container 'Array-Ref' must contain only Hash-refs or Classes at /home/scolesj/database-accessor/lib/Database/Accessor.pm line 583.
Database::Accessor::_create_or_update('Database::Accessor=HASH(0x2686248)', 'CREATE', 'Data::Test=HASH(0x3601448)', 'ARRAY(0x2686290)', undef) called at /home/scolesj/database-accessor/lib/Database/Accessor.pm line 611
Database::Accessor::create('Database::Accessor=HASH(0x2686248)', 'Data::Test=HASH(0x3601448)', 'ARRAY(0x2686290)') called at t/50_create.t line 76
# Looks like your test exited with 255 just after 6.

so I mucked something up.

In the end It turned out I had this this the other day when playing with error messages


confess( $message
. " The \$container 'Array-Ref' must contain only Hash-refs or Classes."
-- if (scalar(@bad) );
++ if (!scalar(@bad) );

Hoisted myself on my own petard there. While I was here I decided to improve this call a little by returning what was entered so now the call looks like this'

confess( $message
. " The \$container 'Array-Ref' must contain only Hash-refs or Classes. \$container="
. Dumper($container) )
if ( scalar(@bad) );
$new_container = $self->_clean_up_container($message,$container);

and give me this error message;


Database::Accessor create( $db 'Class', $container 'Hash-Ref||Class||Array-Ref of [Hash-ref||Class]', $options 'Hash-Ref'); Error: Incorrect Usage:  The $container 'Array-Ref' must contain only Hash-refs or Classes. $container=$VAR1 = [
          {
            'last_name' => 1
          },
          bless( {
                   'first_name' => 'test',
                   'last_name' => 'test'
                 }, 'Data::Test' )
        ];
 at D:\GitHub\database-accessor\lib/Database/Accessor.pm line 583
which actually made finding my petard better as I could see my '$container' was correct so it must be my logic that was wrong.

Now I get a full pass on Database::Accesosor and on Driver::DBI so the day ends well.

probe.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