Little Moose Day

Just a short note for the Moose-Pen toady, I am going to clean finish off my Moose droppings by looking at the Expression.

Well all I really have to do is do a search and replace on the word function in my last post and and then past is here but that would be cheating. If I did do that I would at least see if anyone is reading these apart from Gabor.

So I will be working the 14_predicate.t and adding in the following;


my $expression_1_param = {left=> {name=>'left'},
right=>{expression => '+',
left => {name=>'test'},
right => { param => 3 },
}};
eval {
$predicate = Database::Accessor::Predicate->new($expression_1_param);
};
if ($@) {
fail("expression with 1 param works");
}
else {
pass("expression with 1 param works");
}

ok(ref($predicate->right) eq 'Database::Accessor::Expression','right is a expression');


and as for the function tests I add in one for multi-params and one for mixed-params but no reason to repeat that here.

What I first have to do is have a look at the Expression class


has 'expression' => (
isa => 'Expression',
is => 'rw',
required=>1,
);

and I see that I am going to have to change the name of that 'Expression' type I already have as I want the same name for my Database::Accessor::Expression class so a quick rename in my Constants file

-- use constant EXPRISION => {
++ use constant NUMERIC_OPERATORS => {

the same in my Types.pm

subtype 'NumericOperator',
as 'Str',
where { exists( Database::Accessor::Constants::NUMERIC_OPERATORS->{ uc($_) } ) },
message { "The Numeric Operator '$_', is not a valid Accessor Numeric Operator!"._try_one_of(Database::Accessor::Constants::NUMERIC_OPERATORS()) };

and now then the same pattern in my Types.pm again add in the use, class_type; subtype and fix up coerce statements by adding in 'Expressions' into the '_element_coerce' sub like this

++ if (exists($hash->{expression})){
++ $object = Database::Accessor::Expression->new( %{$hash} );
++}

and run my tests and I get

...
ok 12 - expression with 1 param works
ok 13 - right is a expression
ok 14 - Function with multi params works
ok 15 - Function with mixed params works
ok 16 - My frist right is an Element
ok 17 - My second right is a Param

and that is the little moose for today;

Baby-Moose-10-iStockphoto-.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