add missing newline for no-linenumber-change dzil
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / WithApplicatorDumple.pm
1 package DBIx::Class::DeploymentHandler::WithApplicatorDumple;
2
3 use MooseX::Role::Parameterized;
4 use Module::Runtime 'use_module';
5 use namespace::autoclean;
6
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
14 parameter interface_role => (
15   isa      => 'Str',
16   required => 1,
17 );
18
19 parameter class_name => (
20   isa      => 'Str',
21   required => 1,
22 );
23
24 parameter delegate_name => (
25   isa      => 'Str',
26   required => 1,
27 );
28
29 parameter attributes_to_copy => (
30   isa => 'ArrayRef[Str]',
31   default => sub {[]},
32 );
33
34 parameter attributes_to_assume => (
35   isa => 'ArrayRef[Str]',
36   default => sub {[]},
37 );
38
39 role {
40   my $p = shift;
41
42   my $class_name = $p->class_name;
43
44   use_module($class_name);
45
46   my $meta = Class::MOP::class_of($class_name);
47
48   has $_->name => %{ $_->clone }
49     for grep { $_ } map $meta->find_attribute_by_name($_), @{ $p->attributes_to_copy };
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
69 1;
70
71 # vim: ts=2 sw=2 expandtab
72
73 __END__