1 package MooseX::AttributeHelpers::Composite::Trait;
3 use MooseX::AttributeHelpers::MethodProvider;
4 use MooseX::AttributeHelpers::Meta::Method::Provided;
7 our $AUTHORITY = 'cpan:STEVAN';
12 default => sub { {} },
15 after install_accessors => sub {
17 my $class = $attr->associated_class;
19 my $provides = $attr->provides;
21 foreach my $method_provider (keys %$provides) {
22 my $typename = get_provider_type($method_provider);
23 confess "Attribute must be of type $typename to use $method_provider"
24 unless ($attr->has_type_constraint
25 && $attr->type_constraint->is_a_type_of($typename));
27 my $spec = $provides->{$method_provider};
28 my $factories = get_provider_methods($method_provider, $spec);
30 foreach my $method_name (keys %$factories) {
31 confess "$method_name already exists in class " . $class->name
32 if $class->has_method($method_name);
34 my $method = MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
35 $factories->{$method_name}->(
37 $attr->get_read_method_ref,
38 $attr->get_write_method_ref
41 $attr->associate_method($method);
42 $class->add_method($method_name => $method)
55 MooseX::AttributeHelpers::Composite:Trait
61 use MooseX::AttributeHelpers;
64 #metaclass => 'Composite',
65 traits => ['MooseX::AttributeHelpers::Composite::Trait'],
77 # My::Method::Provider => {
78 # some_method => 'foo_method',
88 print $foo->foo . "\n";
93 This is an expansion on the basic L<MooseX::AttributeHelpers> idea, allowing you
94 to compose the methods provided by the various
95 L<MethodProviders|MooseX::AttributeHelpers::MethodProvider> without naming
96 conflicts. In addition, this module provides a way to get these helper
97 methods without being locked into a particular
98 L<metaclass|MooseX::AttributeHelpers::Composite>, as it is simply a role with
99 a provides attribute and a method modifier. It cannot, however, be used with
100 old-style AttributeHelpers - the 'provides' name will conflict.
108 The map that tells Composite which methods from which providers you would like
109 installed under which names. It follows the format
112 provided_method => desired_method_name,
124 All complex software has bugs lurking in it, and this module is no
125 exception. If you find a bug please either email me, or add the bug
130 Paul Driver E<lt>frodwith@cpan.orgE<gt>