Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Validating against a Moose type-constraint without setting field

by sundialsvc4 (Abbot)
on Nov 15, 2011 at 15:32 UTC ( #938201=perlquestion: print w/ replies, xml ) Need Help??
sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

(Pardon me ... I am having a Senior Moment™ ...)

I need to validate a value against the type-constraint associated with a particular Moose has field, without actually setting the field’s value.   That is to say, given the field name and a variable containing a value that I want to check, I want to fire the field’s validation-constraint if it has one, and see if the value that I am presenting is agreeable to it.   (I had written notes that Moose’s “Recipe #4” told how to do that, but I can’t find that example now.   So, heck, thought I’d just ask...)

Thanks in advance.   (Now, where in the heck did I put my glasses?   Durn things are, uhh, “obviously broken” anyway ...)

Comment on Validating against a Moose type-constraint without setting field
Replies are listed 'Best First'.
Re: Validating against a Moose type-constraint without setting field
by Anonymous Monk on Nov 15, 2011 at 15:37 UTC
Re: Validating against a Moose type-constraint without setting field
by sundialsvc4 (Abbot) on Nov 15, 2011 at 16:49 UTC
    Are you sure about that?   “Meta” doesn’t seem to be it.   My notes said that (I think) Moose::Cookbook::Basics::Recipe4 contained the magic spell, but durned if (squint, peer, wince...) I can see it now.
Re: Validating against a Moose type-constraint without setting field
by stvn (Monsignor) on Nov 23, 2011 at 19:23 UTC

    You want this:

    use Moose::Util::TypeConstraints qw[ find_type_constraint ]; # ... find_type_constraint('MyType')->check( $my_value );
    Basically all this does it locate the underlying type constraint object for you. Alternately you could find the type constraint object in the actual class, which is explain in Moose::Cookbook::Snack::Types.

    -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://938201]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2015-07-07 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls