Off The Moose Track

Well off track again. So I am not going to do my bit on coercion today after all. If anyone out there was actually downloading my code and running my tests you might see this;

Load of Database/Accessor/DAD/Types.pm failed:

Error=Can’t locate Database/Accessor/DAD/Types.pm in @INC (@INC contains: D:GitHubDA-bloglib D:GitHubReplaylib C:/Dwimperl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .) at (eval 378) line 2.

Database/Accessor/DAD/Types (Database::Accessor::DAD::Types) may not be an Database Accessor Driver (DAD)!

Scrolling by as the test all pass. Now this is does not bother me much as all I see here is my Accessor.pm BUILDER code rejecting the load of a non DAD class. To other this may mean that something is going wrong and I am sure, if this project every becomes successful, that I will get all sorts of questions on what is going on here. So it is always better to nip these sort of problems in the bud.

On closer inspection of the above you may notice that it is trying to load the file ‘/Database/Accessor/DAD/Types.pm’ which is odd as there is no file of that name in that folder. The ‘Types.pm’ file is in the ‘/Database/Accessor/’ folder.

So things are not going right in my system at all. At first I though it was this regex

 my ($package) = $_package =~ /^([[:word:]]+(?:::[[:word:]]+)*)$/;

So I got out my old standby buddy The Regex Coach
and I tested the expression and it came out all right so it wasn’t that one. So onto the the next one then;

$dir =~ s/^.+Database/Accessor///;

and a quick warn on the next line showed me



dir=GitHubDA-bloglibDatabaseAccessorDAD

Then that little light clicked on in my brain and I remembered that I am on a windows box so my ‘/’ part in my regex is not going to work as it would on a Linux box where I had orginally used this code, there it would be



dir=/GitHub/DA-blog/lib/Database/Accessor/DAD

I have a few options none of them very elegant, there is most likely a regex out there that will work for both Windows and Linux but I have yet to find one and my regex skills are mediocre at best So I think I will do the brute force approach and just swap out the ” for ‘/’. In the end this small change will make my Accessor more portable across OSes and I do not think I will have any problems as Windows doesn’t care really between the two, ‘dir /foo/bar’ and ‘dir barfor’ and on Linux nothing will change.

Oh by the way I also noticed that I was missing the DAD part on the end of that regex, if you remember in my name-spacestatement from a few posts ago I want all DADs under that name-space , so in the end this is what I came up with;

    $dir =~ s/\///gi;

    $dir =~ s/^.+Database/Accessor/DAD///;

    warn("dir=$dir");

which gives me



dir=

and that is what I want. The code that follows is designed to find DADs that are deeper in the name-space than the DAD level. So a path like this ‘/GitHub/DA-blog/lib/Database/Accessor/DAD/NoSQL/Dimingo,pm would give me the correct class name later on.

Now I also noticed that in my BUILD I also forgot to put the ‘DAD’ in there so with that change

--grep { -d $_ } map { File::Spec->catdir($_, 'Database','Accessor','DAD' ) } @INC;

++grep { -d $_ } map { File::Spec->catdir($_, 'Database','Accessor' ) } @INC;

and this other typo I missed.

--$classname = join '::', 'DA_SC', 'LSD', $package, $file;

++$classname = join '::', 'Database', 'Accessor', 'DAD', $package, $file; 

I reran my tests no more waring about loading a file that does not exists.

Well at least that is some progress.

稿源:blogs.perl.org (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Off The Moose Track

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录