Baby Moose Skips Along

Its think of something, look it up and skip it day here in the Moost-pen.

Yesterday I added in the first option for 'only_elements' and that got me thinking, never good ever comes out of that, I should enforce the rule that 'only_element' option has to be a hash-ref.

So I quickly looked-up a MooseX that I know will let me do that 'MooseX::Params::Validate' and reading a little from Dave's POD I should skip this module and have a look at MooseX::Method::Signatures or MooseX::Declare. Now looking at both of these I see a great big '(DEPRICATED)' on each and this waring in MooseX::Declare;

Warning: MooseX::Declare is based on Devel::Declare, a giant bag of crack originally implemented by mst with the goal of upsetting the perl core developers so much by its very existence that they implemented proper keyword handling in the core.

Ok so I am stepping though a little bit of a midfield here. After some more reading I landed on a bunch more modules such as 'Moops', 'Function::Parameters' and 'Keyword::Simple' all of them had some sort to waring that runs something like this

'The API may change in future versions...'

So there you have the skip for today.

Really I am not trying to introduce method signatures or alike I am just sanitizing my inputs before then go into the DAD, all I really need is a simple sub like this

private_method check_options => sub {
        my $self = shift;
        my ($action,$opt) = @_;
        die "The Option param for $action must be a Hash-Ref"
           if (ref($opt) ne 'HASH');
        foreach my $key (keys(%{$opt})){
             die "The $key option param for $action must be a "
                 ."-Ref not a "
                 . ref($opt->{$key})
                and ref($opt->{$key}) ne Database::Accessor::Constants::OPTIONS->{$key});
where I do a few checks and a new constant 'OPTIONS';

use constant OPTIONS => {
    only_elements =>'HASH'
use constant CRUD =>  {
where I can add in the options as they come up, plus a call to the new sub in execute;

++$self->check_options($action, $opt )
 ++         if ($opt);
and finally of course a few new tests in '62_crud_options.t';

ok($da->retrieve($data),"No param works");
    exception {$da->retrieve($data,[1,1,1]) },
    qr /The Option param for RETRIEVE must be a Hash-Ref/,
    "Caught non hash-ref for param"

my %options = (only_elements=>['first_name','last_name']);

foreach my $key (keys(%options)){
exception {$da->retrieve($data,{$key=>$options{$key}}) },
qr /The $key option param for RETRIEVE must be a/,
"Caught $key must be correct type "

The first two are simple enough, check the '$opt' undef condition works, and next test that the '$ops' must be a hash-ref.

In the last new test I iterate over a hash that as the wrong types in it checking for failure and now I am ready in both and my tests when new options come down the line.

So not much Moose today but here is a pic anyway;


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