add missing newline for no-linenumber-change dzil
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / WithApplicatorDumple.pm
CommitLineData
9f552252 1package DBIx::Class::DeploymentHandler::WithApplicatorDumple;
97aa9a74 2
9f552252 3use MooseX::Role::Parameterized;
7cd51078 4use Module::Runtime 'use_module';
9f552252 5use namespace::autoclean;
6
1b7ebcbf 7# this is at least a little ghetto and not super well
8# thought out. Take a look at the following at some
9# point to clean it all up:
10#
11# http://search.cpan.org/~jjnapiork/MooseX-Role-BuildInstanceOf-0.06/lib/MooseX/Role/BuildInstanceOf.pm
12# http://github.com/rjbs/role-subsystem/blob/master/lib/Role/Subsystem.pm
13
9f552252 14parameter interface_role => (
15 isa => 'Str',
16 required => 1,
17);
18
19parameter class_name => (
20 isa => 'Str',
21 required => 1,
22);
23
24parameter delegate_name => (
25 isa => 'Str',
26 required => 1,
27);
28
9f552252 29parameter attributes_to_copy => (
30 isa => 'ArrayRef[Str]',
31 default => sub {[]},
32);
33
34parameter attributes_to_assume => (
35 isa => 'ArrayRef[Str]',
36 default => sub {[]},
37);
38
39role {
40 my $p = shift;
41
42 my $class_name = $p->class_name;
43
7cd51078 44 use_module($class_name);
9f552252 45
46 my $meta = Class::MOP::class_of($class_name);
47
4f73e4ac 48 has $_->name => %{ $_->clone }
1b7ebcbf 49 for grep { $_ } map $meta->find_attribute_by_name($_), @{ $p->attributes_to_copy };
9f552252 50
51 has $p->delegate_name => (
52 is => 'ro',
53 lazy_build => 1,
54 does => $p->interface_role,
55 handles => $p->interface_role,
56 );
57
58 method '_build_'.$p->delegate_name => sub {
59 my $self = shift;
60
61 $class_name->new({
62 map { $_ => $self->$_ }
63 @{ $p->attributes_to_assume },
64 @{ $p->attributes_to_copy },
65 })
66 };
67};
68
691;
70
71# vim: ts=2 sw=2 expandtab
72
73__END__