1 package Moose::Meta::TypeConstraint::Container;
7 use Scalar::Util 'blessed';
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::TypeConstraint';
15 __PACKAGE__->meta->add_attribute('container_type' => (
16 accessor => 'container_type',
17 predicate => 'has_container_type',
20 sub compile_type_constraint {
23 my $parent_name = $self->parent->name;
25 ($self->has_container_type)
26 || confess "You cannot create a Container type without one";
28 my $container_type = $self->container_type;
30 (blessed $container_type && $container_type->isa('Moose::Meta::TypeConstraint'))
31 || confess "The container type must be a Moose meta type";
35 if ($parent_name eq 'ArrayRef') {
38 ($container_type->check($x)) || return
42 elsif ($parent_name eq 'HashRef') {
44 foreach my $x (values %$_) {
45 ($container_type->check($x)) || return
50 confess "Your isa must be either ArrayRef or HashRef (sorry no subtype support yet)";
53 $self->_set_constraint($constraint);
55 $self->SUPER::compile_type_constraint;
67 Moose::Meta::TypeConstraint::Container
75 =item B<compile_type_constraint>
77 =item B<container_type>
79 =item B<has_container_type>
87 All complex software has bugs lurking in it, and this module is no
88 exception. If you find a bug please either email me, or add the bug
93 Stevan Little E<lt>stevan@iinteractive.comE<gt>
95 =head1 COPYRIGHT AND LICENSE
97 Copyright 2006, 2007 by Infinity Interactive, Inc.
99 L<http://www.iinteractive.com>
101 This library is free software; you can redistribute it and/or modify
102 it under the same terms as Perl itself.