File Coverage

blib/lib/Beam/Wire/Moose.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Beam::Wire::Moose;
2             {
3             $Beam::Wire::Moose::VERSION = '0.003';
4             }
5              
6 2     2   103627 use Moose;
  0            
  0            
7             use Moose::Meta::Class;
8             extends 'Beam::Wire';
9              
10             around create_service => sub {
11             my ( $orig, $self, $name, %service_info ) = @_;
12             if ( my $roles = $service_info{with} ) {
13             my @args = $self->parse_args( %service_info );
14             my @roles = ref $roles eq 'ARRAY' ? @{$roles} : $roles;
15             my $meta = Moose::Meta::Class->create_anon_class(
16             superclasses => [ $service_info{class} ],
17             roles => \@roles,
18             cache => 1,
19             );
20             $service_info{class} = $meta->name;
21             }
22             return $self->$orig( $name, %service_info );
23             };
24              
25             1;
26             __END__
27              
28             =head1 NAME
29              
30             Beam::Wire::Moose - Dependency Injection with extra Moose features
31              
32             =head1 SYNOPSIS
33              
34             # container.yml
35             db:
36             class: My::Database
37             with:
38             - My::Role::Cache
39             - My::Role::Log
40             args:
41             dbh: { ref: dbh }
42             dbh:
43             class: DBI
44             args:
45             - 'dbi:sqlite:data.db'
46              
47             =head1 DESCRIPTION
48              
49             Beam::Wire::Moose is a subclass of Beam::Wire that adds support for Moose-specific
50             features.
51              
52             =head1 SERVICE CONFIG
53              
54             =head2 with
55              
56             Compose roles into this object at run-time. This creates an anonymous class that
57             extends the C<class> config and consumes the roles defined by C<with>.
58              
59             NOTE: This means the service is not an instance of C<class> but an instance of
60             a class that inherits from C<class>. Be cautious when using C<ref> and
61             C<Scalar::Util::blessed>.
62              
63              
64             =head1 SEE ALSO
65              
66             =over 4
67              
68             =item L<Beam::Wire>
69              
70             =back
71