Very Little Dist::Zilla

Only an indirect dist-pen post today.

You ever have one of those days. Your code just does not want to come together and gives you know end of grief. Well today was one of those days for me.

I left off yesterday with what I though was a solution for my problems with 't/30_view.t', by moving my 'Database::Accessor::Roles::DAD' out of Accessor.pm and into its own file. Seem I still had a problem as in the 'Database::Accessor::DAD::Test' I still had a 'use Database::Accessor;' present.

Now that was setting up a circular call to Accessor.pm, as well it was never my intention for some-one to use a DAD directly only as a call from Database::Accessor. In the next test case 't/31_elements.t' I got


RETRIEVE No Database::Accessor::Driver loaded for Data::Test Maybe you have to install a Database::Accessor::DAD::?? for it? at...
# Looks like your test exited with 2 just after 1.

Which I though was a bug in Tests::DAD so I tried this little trick

perl -MDatabase::Accessor::DAD::Test -e 'print Database::Accessor::DAD::Test::VERSION'

Can't locate Database/Accessor/View.pm in @INC (you may need to install the Database::Accessor::View module) (@INC contains: /home/scolesj/database-accessor/lib /home/scolesj/database-accessor/t/lib /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at /home/scolesj/database-accessor/lib/Database/Accessor/Types.pm line 14.

So this led me down what I am very ashamed to say a vary deep rabbit hole. I spend the next hour or two stripping out all those embedded Data::Accessor classed from Accessor.pm and putting them in separate files, I even had to split the Database::Accessor::Types into two files. Long story short I was going nowhere with this.

I now has three separate base classes, two type roles and in the end I was still getting this error


You can only consume roles, Database::Accessor::Roles::DAD is not a Moose role at /usr/local/lib/perl/5.18.2/Moose/Exporter.pm line 419
Moose::with('Database::Accessor::Roles::DAD') called at /home/scolesj/database-accessor/t/lib/Test/Database/Accessor/Utils.pm line 161

In the end it was really just a calling sequence problem. I looked at my Accessor.pm code and I noticed that I do this

my $driver = $drivers->{ ref($conn) };

die "$type No Database::Accessor::Driver loaded for "
. ref($conn)
. " Maybe you have to install a Database::Accessor::DAD::?? for it?"
unless ($driver);
my $dad = $driver->new(


So I never actually need to use the 'Database::Accessor::DAD::Test' but I need some way to get it into the name-space. Now this worked in my Windows box because I had hard-coded the path so it was always finding the DAD.

Well the nice thing about working with git is that I quickly saved this code else where, I may want it some day and rolled back to what I started with.

To get around the sequencing problem all I did was re-embed my 'Database::Accessor::Roles::DAD' role and delteed the separate file. Then as a trick I added the 'Database::Accessor::DAD::Test;' code as a package inside 'Test::Database::Accessor::Utils' and then did this in 't/31_elements.t'


+use lib ('t\lib');
 use Data::Dumper;
 use Data::Test;
+use Database::Accessor;
 use Test::Database::Accessor::Utils;
 use Test::Deep;
-use Test::More tests => 3;
+use Test::More tests => 6;

-BEGIN {
- use_ok('Database::Accessor') || print "Bail out!";
-}


so now the use sequence is correct and my test fully passes

t/20_dad_load.t ............. ok
t/30_view.t ................. ok
t/31_elements.t ............. ok

Oh well live and learn. I am going to keep the separated version about as I have a bad feeling that I am going to run into the same problem when I write up my first proper DAD.

d5f9f1110b5b2115826e3a145e5b8c6e--galactus-godzilla.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