t/202_example_Moose_POOP.t
t/203_example.t
t/204_example_w_DCS.t
+t/205_example_w_TestDeep.t
t/300_immutable_moose.t
t/pod.t
t/pod_coverage.t
B<NOTE:> The C<Undef> type constraint does not work correctly
in every occasion, please use it sparringly.
+
+=head2 Use with Other Constraint Modules
+
+This module should play fairly nicely with other constraint
+modules with only some slight tweaking. The C<where> clause
+in types is expected to be a C<CODE> reference which checks
+it's first argument and returns a bool. Since most constraint
+modules work in a similar way, it should be simple to adapt
+them to work with Moose.
+
+For instance, this is how you could use it with
+L<Declare::Constraint::Simple> to declare a completely new type.
+
+ type 'HashOfArrayOfObjects'
+ => IsHashRef(
+ -keys => HasLength,
+ -values => IsArrayRef( IsObject ));
+
+For more examples see the F<t/204_example_w_DCS.t> test file.
+
+Here is an example of using L<Test::Deep> and it's non-test
+related C<eq_deeply> function.
+
+ type 'ArrayOfHashOfBarsAndRandomNumbers'
+ => where {
+ eq_deeply($_,
+ array_each(subhashof({
+ bar => isa('Bar'),
+ random_number => ignore()
+ })))
+ };
+
+For a complete example see the F<t/205_example_w_TestDeep.t>
+test file.
=head1 FUNCTIONS
use Test::More;
+=pod
+
+This tests how well Moose type constraints
+play with Declare::Constraints::Simple.
+
+Pretty well if I do say so myself :)
+
+=cut
+
BEGIN {
eval "use Declare::Constraints::Simple;";
plan skip_all => "Declare::Constraints::Simple is required for this test" if $@;
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+=pod
+
+This tests how well Moose type constraints
+play with Test::Deep.
+
+Its not as pretty as Declare::Constraints::Simple,
+but it is not completely horrid either.
+
+=cut
+
+BEGIN {
+ eval "use Test::Deep;";
+ plan skip_all => "Test::Deep is required for this test" if $@;
+ plan tests => 7;
+}
+
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+ use_ok('Moose::Util::TypeConstraints');
+}
+
+{
+ package Foo;
+ use Moose;
+ use Moose::Util::TypeConstraints;
+
+ use Test::Deep qw[
+ eq_deeply array_each subhashof ignore
+ ];
+
+ # define your own type ...
+ type 'ArrayOfHashOfBarsAndRandomNumbers'
+ => where {
+ eq_deeply($_,
+ array_each(
+ subhashof({
+ bar => Test::Deep::isa('Bar'),
+ random_number => ignore()
+ })
+ )
+ )
+ };
+
+ has 'bar' => (
+ is => 'rw',
+ isa => 'ArrayOfHashOfBarsAndRandomNumbers',
+ );
+
+ package Bar;
+ use Moose;
+}
+
+my $array_of_hashes = [
+ { bar => Bar->new, random_number => 10 },
+ { bar => Bar->new },
+];
+
+my $foo;
+lives_ok {
+ $foo = Foo->new('bar' => $array_of_hashes);
+} '... construction succeeded';
+isa_ok($foo, 'Foo');
+
+is_deeply($foo->bar, $array_of_hashes, '... got our value correctly');
+
+dies_ok {
+ $foo->bar({});
+} '... validation failed correctly';
+
+dies_ok {
+ $foo->bar([{ foo => 3 }]);
+} '... validation failed correctly';
+
+