File Coverage

blib/lib/Beam/Wire/Moose.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Beam::Wire::Moose;
2             # ABSTRACT: Dependency Injection with extra Moose features
3             $Beam::Wire::Moose::VERSION = '0.005';
4 1     1   28002 use Moose;
  1         501807  
  1         7  
5 1     1   7157 use Moose::Meta::Class;
  1         3  
  1         226  
6             extends 'Beam::Wire';
7              
8             around create_service => sub {
9             my ( $orig, $self, $name, %service_info ) = @_;
10             if ( my $roles = $service_info{with} ) {
11             my @args = $self->parse_args( %service_info );
12             my @roles = ref $roles eq 'ARRAY' ? @{$roles} : $roles;
13             my $meta = Moose::Meta::Class->create_anon_class(
14             superclasses => [ $service_info{class} ],
15             roles => \@roles,
16             cache => 1,
17             );
18             $service_info{class} = $meta->name;
19             }
20             return $self->$orig( $name, %service_info );
21             };
22              
23             1;
24              
25             __END__
26              
27             =pod
28              
29             =head1 NAME
30              
31             Beam::Wire::Moose - Dependency Injection with extra Moose features
32              
33             =head1 VERSION
34              
35             version 0.005
36              
37             =head1 SYNOPSIS
38              
39             # container.yml
40             db:
41             class: My::Database
42             with:
43             - My::Role::Cache
44             - My::Role::Log
45             args:
46             dbh: { ref: dbh }
47             dbh:
48             class: DBI
49             args:
50             - 'dbi:sqlite:data.db'
51              
52             =head1 DESCRIPTION
53              
54             Beam::Wire::Moose is a subclass of Beam::Wire that adds support for Moose-specific
55             features.
56              
57             =head1 SERVICE CONFIG
58              
59             =head2 with
60              
61             Compose roles into this object at run-time. This creates an anonymous class that
62             extends the C<class> config and consumes the roles defined by C<with>.
63              
64             NOTE: This means the service is not an instance of C<class> but an instance of
65             a class that inherits from C<class>. Be cautious when using C<ref> and
66             C<Scalar::Util::blessed>.
67              
68             =head1 SEE ALSO
69              
70             =over 4
71              
72             =item L<Beam::Wire>
73              
74             =back
75              
76             =head1 AUTHOR
77              
78             Doug Bell <preaction@cpan.org>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is copyright (c) 2015 by Doug Bell.
83              
84             This is free software; you can redistribute it and/or modify it under
85             the same terms as the Perl 5 programming language system itself.
86              
87             =cut