| 1 | package Beam::Service; | ||
| 2 | 2 | our $VERSION = '0.001'; | |
| 3 | # ABSTRACT: Role for services to access Beam::Wire features | ||
| 4 | |||
| 5 | #pod =head1 SYNOPSIS | ||
| 6 | #pod | ||
| 7 | #pod package My::Object; | ||
| 8 | #pod use Role::Tiny::With; # or Moo, or Moose | ||
| 9 | #pod with 'Beam::Service'; | ||
| 10 | #pod | ||
| 11 | #pod package main; | ||
| 12 | #pod use Beam::Wire; | ||
| 13 | #pod my $wire = Beam::Wire->new( | ||
| 14 | #pod config => { | ||
| 15 | #pod my_object => { | ||
| 16 | #pod '$class' => 'My::Object', | ||
| 17 | #pod }, | ||
| 18 | #pod }, | ||
| 19 | #pod ); | ||
| 20 | #pod | ||
| 21 | #pod print $wire->get( 'my_object' )->name; # my_object | ||
| 22 | #pod | ||
| 23 | #pod =head1 DESCRIPTION | ||
| 24 | #pod | ||
| 25 | #pod This role adds extra functionality to an object that is going to be used | ||
| 26 | #pod as a service in a L<Beam::Wire> container. While any object can be | ||
| 27 | #pod configured with Beam::Wire, consuming the Beam::Service role allows an | ||
| 28 | #pod object to know its own name and to access the container it was | ||
| 29 | #pod configured in to fetch other objects that it needs. | ||
| 30 | #pod | ||
| 31 | #pod =head1 SEE ALSO | ||
| 32 | #pod | ||
| 33 | #pod L<Beam::Wire> | ||
| 34 | #pod | ||
| 35 | #pod =cut | ||
| 36 | |||
| 37 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 2 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | 2 | ▶ | use Types::Standard qw( Str InstanceOf ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 41 | |||
| 42 | #pod =attr name | ||
| 43 | #pod | ||
| 44 | #pod The name of the service. This is the name used in the L<Beam::Wire> | ||
| 45 | #pod configuration file for this service. | ||
| 46 | #pod | ||
| 47 | #pod =cut | ||
| 48 | |||
| 49 | 2 | has name => ( | |
| 50 | is => 'ro', | ||
| 51 | isa => Str, | ||
| 52 | ); | ||
| 53 | |||
| 54 | #pod =attr container | ||
| 55 | #pod | ||
| 56 | #pod The L<Beam::Wire> container object that contained this service. Using | ||
| 57 | #pod this container we can get other services as-needed. | ||
| 58 | #pod | ||
| 59 | #pod =cut | ||
| 60 | |||
| 61 | 2 | has container => ( | |
| 62 | is => 'ro', | ||
| 63 | isa => InstanceOf['Beam::Wire'], | ||
| 64 | ); | ||
| 65 | |||
| 66 | 2 | 1; | |
| 67 | |||
| 68 | __END__ | ||