CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Using Param::validate (cpan param validation module) to validate a specific object type

 



perlFun
Novice

Aug 20, 2013, 4:39 PM

Post #1 of 2 (992 views)
Using Param::validate (cpan param validation module) to validate a specific object type Can't Post

I'm used to using Param::validate in the following way:

my %opts = validate (
@_, {
incomingParam =>
{ type => ARRAYREF,
optional => 0,
},
}
);#end param validation


Where I have a scalar, arrayref, or hashref. Now I need to validate a specific object type. I looked at the cpan documentation and say the following types are allowed:

http://search.cpan.org/~drolsky/Params-Validate-1.08/lib/Params/Validate.pm (look at the section on Type Validation)

Specific you can specify "Object" if it's a blessed object, which my param is. But do you know if I can specify the type of object it is? I would like it to be a bit more specific than that, if possible, to use say an object that I myself have created.


perlFun
Novice

Aug 20, 2013, 4:58 PM

Post #2 of 2 (990 views)
Re: [perlFun] Using Param::validate (cpan param validation module) to validate a specific object type [In reply to] Can't Post

Nevermind, I'm not certain how I overlooked it the first time through but the answer is right here for anyone curious:

validate(
@_,
# must be both, not either!
{ foo => { isa => [qw( My::Frobnicator IO::Handle )] } }
);

(can specific it is one of those object types)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives