More Noise From the Play Pen

Well in today’s playpen I am going to carry on from my last post and get my new name-space all in order so it looks like a re-factor day today. Some of you may of noticed good number of places where I could use all sorts of Moose goodies to save my self time and typing. For example I could create number of roles for the common attributes across my classes or maybe coercion on some of my attributes. Now might seem like a good time to do that.

Well what I have discovered over the years, and some old salts might agree with me on this, is that it is always prudent to build back to last working instance when doing a re-factoring or re-naming, to keep the changes to a minimum and have a point you can quickly get back to.

So rather than trying to bight off too much right now I only did a re-naming and a slight change to my loading function. The first thing I started with was getting my 02_basic test up and ready to go by stripping out the timing stuff.

Next there was the name change from 'DA::' over to 'Database::Accessor' in all my code and once doen I ran my tests.

Now the only exciting thing that happened is couldn't get my DADs (this is what I am calling LSDs now) to load as I was getting this


# Failed test 'use Database::Accessor::View;'
# at 02_base_Accessor.t line 42.
# Tried to use 'Database::Accessor::View'.
# Error: Can't locate Database/Accessor/View.pm in
...

After some poking about I discovered my mistake and it was the good dyslexia in combination with a search and replace in Accessor.pm (that is the new name of the DA.pm file) so to my chagrin Acessor is not the same as Accessor.

Well another search and replace and all was fine.

In this re-factoring exercise I found it necessary to make the '_loadLSDClassesFromDir' sub in Accessor.pm recursive, meaning that it can now drill down into folders. Now the reason for is that it allows end users to install a DAD in a name-space that may be off main perl lib dir or have thier own private DAD. I also took the opportunity to rename it ll to '_loadDADClassesFromDir' So from what I had stubbed in before all I really needed to do was this


my ($path,$dad) = @_;
$dad = {}
if (ref($dad) ne 'HASH');
...
if (-d $_) {
$self->_loadLSDClassesFromDir($_);

$dir =~ s/^.+Database\/Accessor\///;
my $_package = join '::' => grep $_ => File::Spec->splitdir($dir);
# # untaint that puppy!
my ($package) = $_package =~ /^([[:word:]]+(?:::[[:word:]]+)*)$/;
my $classname = "";
if ($package) {
$classname = join '::', 'Database', 'Accessor', $package, $file;
}
else {
$classname = join '::','Database', 'Accessor', 'DAD', $file;
}

I first expanded my sub so it takes the $dad as a param and then I recursively call myself if $_ is a 'dir' and pass along to $dad hashref. I then convert the path to a ptemp ackage name, if that temp ame can be converted to a single package name I use that to create the $classname rather than just the file name.

You may also notice I changed the name of the required function in my DAD role to


requires 'DB_Class';
requires 'Execute';

So I what I am trying to express here is that functions that are required by the DAD role to be Upper Camel case and I will have to add that my name-space statement with the line like;
The letter case used in functions is significance. Any required functions from the DAD role will be in Upper Camel with '_' between words.

So in this round I kept my change set quite small.

  1. rename of my name-spaces

  2. rename a few of my Accessor functions and atrributes

  3. rename of the required DAD Role functions and

  4. small expansion of the _ loadDADClassesFromDir function


And with that I ran my new tests and the all pass. Even this small change-set it took me a good hour or so to fully fix it up. Imagine if I tried to do allsorts of other changes!

Anyway time to move forward.

in_the water.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