Moose Attributes Cheeper by the Doz

So today in the Moose-pen I am going to stub in the rest of my Database::Accessor classes and the rest of my Accessor.pm attributes.

It seems I have six outstanting Database::Accessor classes to add in namely;


  • Param

  • Condition

  • Link

  • Gather

  • Filter

  • Sort


That was easy enough just a quick copy and rename job of the Predicate class without its attributes, so six more classes like this one

package
Database::Accessor::Param;
use Moose;
with qw(Database::Accessor::Roles::Base);
has '+name' => ( required => 0 );
1;

Now I quickly realized I should update my Roles a little seems that

has '+name' => ( required => 0 );

is reused seven times. Thinking one step ahead again, in SQL there are really only three SQL clauses that would use an alias so that makes to take that required out the base and have in only on the ones with alias.

So in 'Database::Accessor::Roles::Base' I do this


-- required => 1,

in my View, Element and Filter classes I add in

with qw(Database::Accessor::Roles::Alias);
has '+name' => ( required => 1 );

and I take out

has '+name' => ( required => 0 );

from the other classes, so a little space saved. Now of course I have add in all the tests for those and though I think I can drop the test for having alias from all the ones after I Predicate.

Now comes my Accessor.pm Attributes and I have a few of those to stub in. At one time I was thinking of having only Attributes that are set instance creation 'ro' in Moose speak. I soon dropped that idea as it would limit DataBase::Accessor to just a static data dumper.

Now if I made them all Read write, 'rw' in Moose speak, that would make the system much too open. Any Data Molder trying to use Accessor would be very pissed if she when to all the trouble of setting up an Accessor object only to have some programmer change it all about when they use it.

So I have to come up with a compromise where all the static attributes are part of the DataBase::Accessor and the dynamic attributes are part of the loaded DAD which I have already set up to have a 'ro' copy of the Accessors attributes.
It is my Database::Accessor::Roles::DAD that will set all this up.

This should create the situation where my static attributes never go away during the lime on an instance and the dynamic can be added and dropped as required.

So here are the attributes from Accesssor class

  • view
  • elements
  • conditions
  • links
  • gathers
  • filters
  • sorts

and their static and dynamic counterparts in the DAD Role

Static:

  • View
  • Elements
  • Conditions
  • Links
  • Gathers
  • Filters
  • Sorts

Dynamic:

  • elements
  • conditions
  • links
  • gathers
  • filters
  • sorts

You will note that I have no provision to add in multiple view (tables in SQL or collections in non-sql) that is deliberate on my part and I know it is just bad SQL to have more that one 'Table' in a 'From' clause and likewise in Mongo you can only work with a single collection at a time (mostly).

So the idea is to give the DAD a full suite of classes that they can put to use create 'clauses' for an SQL query or in the case of Mongo a query and projection.

So lots added today. Will have to get all the test in order once again, at least I have a subject for tomorrow's post

doz-moose.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