1MooseX::Meta::TypeConstUrsaeirntC:o:nFtorriMcboeuoCtsoeeedXr:cP:ieMorenlt(a3D:)o:cTuympeenCtoantsitornaint::ForceCoercion(3)
2
3
4
6 MooseX::Meta::TypeConstraint::ForceCoercion - Force coercion when
7 validating type constraints
8
10 version 0.01
11
13 use MooseX::Types:::Moose qw/Str Any/;
14 use Moose::Util::TypeConstraints;
15 use MooseX::Meta::TypeConstraint::ForceCoercion;
16
17 # get any type constraint
18 my $tc = Str;
19
20 # declare one or more coercions for it
21 coerce $tc,
22 from Any,
23 via { ... };
24
25 # wrap the $tc to force coercion
26 my $coercing_tc = MooseX::Meta::TypeConstraint::ForceCoercion->new(
27 type_constraint => $tc,
28 );
29
30 # check a value against new type constraint. this will run the type
31 # coercions for the wrapped type, even if the value already passes
32 # validation before coercion. it will fail if the value couldn't be
33 # coerced
34 $coercing_tc->check('Affe');
35
37 This class allows to wrap any "Moose::Meta::TypeConstraint" in a way
38 that will force coercion of the value when checking or validating a
39 value against it.
40
42 type_constraint
43 The type constraint to wrap. All methods except for "validate" and
44 "check" are delegated to the value of this attribute.
45
47 check ($value)
48 Same as "Moose::Meta::TypeConstraint::check", except it will always try
49 to coerce $value before checking it against the actual type constraint.
50 If coercing fails the check will fail, too.
51
52 validate ($value, $coerced_ref?)
53 Same as "Moose::Meta::TypeConstraint::validate", except it will always
54 try to coerce $value before validating it against the actual type
55 constraint. If coercing fails the validation will fail, too.
56
57 If coercion was successful and a $coerced_ref references was passed,
58 the coerced value will be stored in that.
59
61 Florian Ragwitz <rafl@debian.org>
62
64 This software is copyright (c) 2009 by Florian Ragwitz.
65
66 This is free software; you can redistribute it and/or modify it under
67 the same terms as perl itself.
68
69
70
71perl v5.32.1 Mo2o0s2e1X-:0:1M-e2t7a::TypeConstraint::ForceCoercion(3)