| 1 | package Bread::Board::Literal; | ||
| 2 | 64 | our $AUTHORITY = 'cpan:STEVAN'; | |
| 3 | # ABSTRACT: service providing a literal value | ||
| 4 | 64 | $Bread::Board::Literal::VERSION = '0.35'; | |
| 5 | 64 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 64 | with 'Bread::Board::Service'; | |
| 8 | |||
| 9 | 64 | has 'value' => ( | |
| 10 | is => 'rw', | ||
| 11 | required => 1, | ||
| 12 | ); | ||
| 13 | |||
| 14 | 141 | ▶ | sub get { (shift)->value } |
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||
| 15 | |||
| 16 | sub clone_and_inherit_params { | ||
| 17 | 1 | ▶ | confess 'Trying to inherit from a literal service'; |
|
Subroutine
clone_and_inherit_params: called CC=1 SCAR=0.0
Pod
documented
| |||
| 18 | } | ||
| 19 | |||
| 20 | 64 | __PACKAGE__->meta->make_immutable; | |
| 21 | |||
| 22 | 64 | ▶ | no Moose; 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | __END__ | ||
| 25 | |||
| 26 | =pod | ||
| 27 | |||
| 28 | =encoding UTF-8 | ||
| 29 | |||
| 30 | =head1 NAME | ||
| 31 | |||
| 32 | Bread::Board::Literal - service providing a literal value | ||
| 33 | |||
| 34 | =head1 VERSION | ||
| 35 | |||
| 36 | version 0.35 | ||
| 37 | |||
| 38 | =head1 SYNOPSIS | ||
| 39 | |||
| 40 | my $c = container PrettyBoring => as { | ||
| 41 | |||
| 42 | # These are Bread::Board::Literal services | ||
| 43 | service connect_string => 'dbi:mysql:boring_db'; | ||
| 44 | service service_url => 'http://api.example.com/v0/boring'; | ||
| 45 | |||
| 46 | # And some other services depending on them... | ||
| 47 | |||
| 48 | service dbconn => ( | ||
| 49 | class => 'DBI', | ||
| 50 | block => sub { | ||
| 51 | my $s = shift; | ||
| 52 | DBI->new($s->param('connect_string'); | ||
| 53 | }, | ||
| 54 | dependencies => wire_names(qw( connect_string )), | ||
| 55 | ); | ||
| 56 | |||
| 57 | service service_request => ( | ||
| 58 | class => 'HTTP::Request', | ||
| 59 | block => sub { | ||
| 60 | my $s = shift; | ||
| 61 | HTTP::Request->new(POST => $s->param('service_url')); | ||
| 62 | }, | ||
| 63 | dependencies => wire_names(qw( service_url )); | ||
| 64 | }; | ||
| 65 | }; | ||
| 66 | |||
| 67 | # OR to use directly: | ||
| 68 | my $literal = Bread::Board::Literal->new( | ||
| 69 | name => 'the_answer_to_life_the_universe_and_everything', | ||
| 70 | value => 42, | ||
| 71 | ); | ||
| 72 | $c->add_service($literal); | ||
| 73 | |||
| 74 | =head1 DESCRIPTION | ||
| 75 | |||
| 76 | A literal service is one that stores a literal scalar or reference for use in | ||
| 77 | your Bread::Board. | ||
| 78 | |||
| 79 | Beware of using references in your literals as they may cause your Bread::Board | ||
| 80 | to leak memory. If this is a concern, you may want to weaken your references. | ||
| 81 | |||
| 82 | See L<Scalar::Util/weaken>. | ||
| 83 | |||
| 84 | =head1 ATTRIBUTES | ||
| 85 | |||
| 86 | =head2 C<value> | ||
| 87 | |||
| 88 | Required attribute with read/write accessor. This is the value that | ||
| 89 | L</get> will return. | ||
| 90 | |||
| 91 | =head1 METHODS | ||
| 92 | |||
| 93 | =over 4 | ||
| 94 | |||
| 95 | =head2 C<get> | ||
| 96 | |||
| 97 | Returns the L</value>, unaltered. | ||
| 98 | |||
| 99 | =head2 C<clone_and_inherit_params> | ||
| 100 | |||
| 101 | Dies: a literal service is (essentially) a constant, it does not make | ||
| 102 | sense to inherit from it. | ||
| 103 | |||
| 104 | =head1 AUTHOR | ||
| 105 | |||
| 106 | Stevan Little <stevan@iinteractive.com> | ||
| 107 | |||
| 108 | =head1 BUGS | ||
| 109 | |||
| 110 | Please report any bugs or feature requests on the bugtracker website | ||
| 111 | https://github.com/stevan/BreadBoard/issues | ||
| 112 | |||
| 113 | When submitting a bug or request, please include a test-file or a | ||
| 114 | patch to an existing test-file that illustrates the bug or desired | ||
| 115 | feature. | ||
| 116 | |||
| 117 | =head1 COPYRIGHT AND LICENSE | ||
| 118 | |||
| 119 | This software is copyright (c) 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive. | ||
| 120 | |||
| 121 | This is free software; you can redistribute it and/or modify it under | ||
| 122 | the same terms as the Perl 5 programming language system itself. | ||
| 123 | |||
| 124 | =cut | ||