--- /dev/null
+package MooseX::AttributeHelpers::Composite::Trait;
+use Moose::Role;
+use MooseX::AttributeHelpers::MethodProvider;
+use MooseX::AttributeHelpers::Meta::Method::Provided;
+
+has provides => (
+ is => 'ro',
+ isa => 'HashRef',
+ default => sub { {} },
+);
+
+after install_accessors => sub {
+ my $attr = shift;
+ my $class = $attr->associated_class;
+
+ my $provides = $attr->provides;
+
+ foreach my $method_provider (keys %$provides) {
+ my $typename = get_provider_type($method_provider);
+ confess "Attribute must be of type $typename to use $method_provider"
+ unless ($attr->has_type_constraint
+ && $attr->type_constraint->is_a_type_of($typename));
+
+ my $spec = $provides->{$method_provider};
+ my $factories = get_provider_methods($method_provider, $spec);
+
+ foreach my $method_name (keys %$factories) {
+ confess "$method_name already exists in class " . $class->name
+ if $class->has_method($method_name);
+
+ my $method = MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
+ $factories->{$method_name}->(
+ $attr,
+ $attr->get_read_method_ref,
+ $attr->get_write_method_ref
+ ),
+ );
+ $attr->associate_method($method);
+ $class->add_method($method_name => $method)
+ }
+ }
+};
+
+1;