more tests and tweaks
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Collection.pm
CommitLineData
8c651099 1
2package MooseX::AttributeHelpers::Collection;
3use Moose;
4use Moose::Util::TypeConstraints;
5
6our $VERSION = '0.01';
7our $AUTHORITY = 'cpan:STEVAN';
8
9extends 'MooseX::AttributeHelpers::Base';
10
11has 'container_type' => (
12 is => 'ro',
13 isa => 'Str',
14 predicate => 'has_container_type',
15);
16
17has 'container_type_constraint' => (
18 is => 'rw',
19 isa => 'Moose::Meta::TypeConstraint',
20 lazy => 1,
21 default => sub {
22 my $self = shift;
23 ($self->has_container_type)
24 || confess "You cannot create a container_type_constraint if you dont have a container type";
25
26 my $container_type = $self->container_type;
27 my $constraint = find_type_constraint($container_type);
69dde336 28
29 # NOTE:
30 # I am not sure DWIM-ery is a good thing
31 # here, so i am going to err on the side
32 # of caution, and blow up if you have
33 # not made a type constraint for this yet.
34 # - SL
35 (defined $constraint)
36 || confess "You must predefine the '$container_type' constraint before you can use it as a container type";
8c651099 37
38 return $constraint;
39 }
40);
41
42before 'process_options_for_provides' => sub {
43 my ($self, $options) = @_;
44
45 if (exists $options->{isa}) {
46 my $type = $options->{isa};
47 if ($type =~ /^(.*)\[(.*)\]$/) {
48 my $core_type = $1;
49 my $container_type = $2;
50 $options->{isa} = $core_type;
51 $options->{container_type} = $container_type;
52 }
53 }
54};
55
56no Moose;
c25a396f 57no Moose::Util::TypeConstraints;
8c651099 58
591;
60
61__END__
62
63=pod
64
65=head1 NAME
66
67=head1 SYNOPSIS
68
69=head1 DESCRIPTION
70
71=head1 METHODS
72
73=head1 BUGS
74
75All complex software has bugs lurking in it, and this module is no
76exception. If you find a bug please either email me, or add the bug
77to cpan-RT.
78
79=head1 AUTHOR
80
81Stevan Little E<lt>stevan@iinteractive.comE<gt>
82
83=head1 COPYRIGHT AND LICENSE
84
85Copyright 2007 by Infinity Interactive, Inc.
86
87L<http://www.iinteractive.com>
88
89This library is free software; you can redistribute it and/or modify
90it under the same terms as Perl itself.
91
92=cut