1 package MooseX::AttributeHelpers::MethodProvider;
7 use Exporter qw(import);
8 our @EXPORT = qw(get_provider_methods add_method_provider get_provider_type);
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
15 sub get_provider_type {
17 return $REGISTRY{$name}->{type} || confess "No provider named $name";
20 sub get_provider_methods {
21 my ($name, $how) = @_;
24 my $methods = $REGISTRY{$name}->{provides}
25 || confess "No provider named $name";
31 if (ref $how eq 'ARRAY') {
34 $_ => $methods->{$_} || confess "No factory named $_"
39 if (ref $how eq 'HASH') {
42 my ($old, $new) = ($_, $how->{$_});
43 $new => $methods->{$old} || confess "No factory named $old"
48 confess "Don't know to get provider methods by $how";
51 sub add_method_provider ($;%) {
52 my ($name, %options) = @_;
54 confess "Already a method provider named $name"
55 if exists $REGISTRY{$name};
57 my $method_map = $options{provides} or confess "No factories provided";
59 my $consumes = $options{consumes};
60 foreach my $provider (keys %$consumes) {
61 my $methods = get_provider_methods($provider, $consumes->{$provider});
62 foreach (keys %$methods) {
63 confess "Method $_ already provided" if exists $method_map->{$_};
64 $method_map->{$_} = $methods->{$_};
69 type => $options{type} || 'Any',
70 provides => $method_map,