Object-InsideOut - Re: More types?

Posted on Mon Nov 21 18:58:34 2005 by jdhedden in response to 1355 (See the whole thread of 3)
Re: More types?
> Have you considered adding more options to the 'Type' attribute?

Because you asked, I added custom type checking in Object::InsideOut v1.13. Check here for the announcement.

> 1. If I want the type to be a scalar, I can say 'Type' => '', right?

No, that results in no type checking at all. Using custom type checking in the OIO 1.13, you can achieve SCALAR type checking like this:
my @data :Field('Accessor' => 'data', 'Type' => sub { ! ref($_[0]) } );

> 2. If you have 'NUMERIC', why not have 'INTEGER' ?

I originally put in 'NUMERIC' because it was so simple using Scalar::Util::looks_like_number(). Other numerical checks would have taken more code. Now, with custom type checking you can define whatever you need. See the announcement post for an example of INTEGER type checking.

> 3. In my program, I have a lot of 'POSITIVE' (Integers > 0).

Here's an example for that:
package My::Class; { use Object::InsideOut; sub positive : Private { return (Scalar::Util::looks_like_number($_[0]) && ($_[0] > 0)); } my @num :Field('Acc' => 'num', 'type' => \&My::Class::positive); }

> 4. I wish there was a way to specify 'ARRAY', where anything but an array ref is an error.

Okay. I added two new types for that: 'ARRAY_REF', and 'HASH_REF'

Thanks for the inspiration. Hope it all works for you.
Direct Responses: 1377 | Write a response