summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Bread/Board/Role/Object.pm
blob: e99e5ed3cca23edf2c983b00c5c74806bdfce50d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package MooseX::Bread::Board::Role::Object;
use Moose::Role;

has name => (
    is      => 'rw',
    isa     => 'Str',
    lazy    => 1,
    default => sub { shift->meta->name },
);

sub BUILD { }
after BUILD => sub {
    my $self = shift;

    my $meta = Class::MOP::class_of($self);

    for my $service ($meta->get_all_services) {
        if ($service->isa('MooseX::Bread::Board::BlockInjection')) {
            my $block = $service->block;
            $self->add_service(
                $service->clone(
                    block => sub {
                        $block->(@_, $self)
                    },
                )
            );
        }
        else {
            $self->add_service($service->clone);
        }
    }
};

no Moose::Role;

1;