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