Baby Moose Back Again?

Well its Accessor.pm post-ette day today here in the Moose-Pen

Yesterday's post I managed to make a very small start on my Driver::DBI before I figured it would be a good idea to do more of the param validation on the Accessor side rather than the driver side. That way I know I will not run into the situation where one Accessor/Driver combination works differently than another.

The validation rule for today is on the $container param for both the Create and Update and is as follows;

'Each element in the elements array that has the same view as the DA class must be present as a key in a Hash-ref or as an attribute in Class container. This rule is not on by default but is to be turned on only when the all_elements_present flag is true.

So to get the above in place I will need to add in that new flag here;


has [
qw(da_compose_only
da_no_effect
da_warning
++ all_elements_present
...

Now for the validation I created the neat little recursive sub;

sub _all_elements_present {
my $self = shift;
my ( $message, $container ) = @_;

if ( ref($container) eq "ARRAY" ) {
$message.=” The Array-ref container, has an error! “;
foreach my $sub_container ( @{$container} ) {
$self->_all_elements_present($message,$sub_container);
}
}
else {
foreach my $element ( $self->elements() ) {
next
if ( !( $element->view )
and $element->view ne $self->view->name() )
; #ignore elements on other view (joins etc)
if ( ref($container) eq 'HASH' ) {
die $message
. "The Hash-Ref \$container must have a "
. $element->name
. " key present!"
if ( !exists( $container->{ $element->name } ) );
}
else {
die $message
. "The Class \$container must have a "
. $element->name
. " attribute!"
if ( !( $container->can( $element->name ) ) );
}
}
}
}


and then a quick add in to the create and update methods

++ $self->_all_elements_present($message,$container)
++ if ($self->all_elements_present);
$self->_execute( Database::Accessor::Constants::CREATE,


and

++ $self->_all_elements_present($message,$container)
++ if ($self->all_elements_present);
$self->_execute( Database::Accessor::Constants::UPDATE,

and that should be good to go. A start on it anyway, I see in some of my earlier notes I am going to a few element attributes to handle as well here is a partial list

  • no_create
  • no_retrieve
  • no_update
  • is_identity
  • only_retrieve

and some of these are not even in Accessor.pm yet.

I do not think I am ever going to get to play in Driver::DBI, as I need code and tests for all of the above to boot and I just saw one other rule I will have to add, all elements on a create or update must have the same view. Oh well more posts at least.


baby 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