adding some crap in
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Base.pm
CommitLineData
d26633fc 1
2package MooseX::AttributeHelpers::Base;
3use Moose;
4
5our $VERSION = '0.01';
6our $AUTHORITY = 'cpan:STEVAN';
7
8extends 'Moose::Meta::Attribute';
9
10has 'method_constructors' => (
11 is => 'ro',
12 isa => 'HashRef',
13 default => sub { {} }
14);
15
16has 'provides' => (
17 is => 'ro',
18 isa => 'HashRef',
19 required => 1,
20);
21
8881a8d3 22# extend the parents stuff to make sure
23# certain bits are now required ...
d26633fc 24has '+$!default' => (required => 1);
25has '+type_constraint' => (required => 1);
26
8881a8d3 27# this confirms that provides has
28# all valid possibilities in it
d26633fc 29sub _check_provides {
30 my ($self, $provides) = @_;
31 my $method_constructors = $self->method_constructors;
32 foreach my $key (keys %$provides) {
33 (exists $method_constructors->{$key})
34 || confess "$key is an unsupported method type";
35 }
36}
37
8881a8d3 38# this provides an opportunity to
39# manipulate the %options to handle
40# some of the provides features
41# correctly.
d26633fc 42sub _process_options_for_provides {
43 my ($self, $options) = @_;
44 # ...
45}
46
47before '_process_options' => sub {
48 my ($self, %options) = @_;
d26633fc 49 if (exists $options{provides}) {
50 $self->_check_provides($options{provides});
51 $self->_process_options_for_provides(\%options);
52 }
53};
54
55after 'install_accessors' => sub {
56 my $attr = shift;
57 my $class = $attr->associated_class;
58
59 my $method_constructors = $attr->method_constructors;
60
61 foreach my $key (keys %{$attr->provides}) {
62 $class->add_method(
63 $attr->provides->{$key},
64 $method_constructors->{$key}->($attr)
65 );
66 }
67};
68
69no Moose;
d26633fc 70
711;
72
73__END__
74
75=pod
76
77=head1 NAME
78
79MooseX::AttributeHelpers::Base
80
81=head1 SYNOPSIS
82
83=head1 DESCRIPTION
84
85=head1 METHODS
86
87=head1 BUGS
88
89All complex software has bugs lurking in it, and this module is no
90exception. If you find a bug please either email me, or add the bug
91to cpan-RT.
92
93=head1 AUTHOR
94
95Stevan Little E<lt>stevan@iinteractive.comE<gt>
96
97=head1 COPYRIGHT AND LICENSE
98
99Copyright 2007 by Infinity Interactive, Inc.
100
101L<http://www.iinteractive.com>
102
103This library is free software; you can redistribute it and/or modify
104it under the same terms as Perl itself.
105
106=cut