File Coverage

blib/lib/Bolts/Blueprint/Literal.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 3 3 100.0
total 18 18 100.0


line stmt bran cond sub pod time code
1             package Bolts::Blueprint::Literal;
2             $Bolts::Blueprint::Literal::VERSION = '0.142930';
3             # ABSTRACT: A blueprint that points to a literal value
4              
5 8     8   38 use Moose;
  8         14  
  8         49  
6              
7             with 'Bolts::Blueprint::Role::Injector';
8              
9 8     8   38682 use Carp ();
  8         19  
  8         686  
10              
11              
12             has value => (
13             is => 'ro',
14             required => 1,
15             );
16              
17              
18             sub builder {
19 86     86 1 114 my ($self) = @_;
20 86         2351 $self->value;
21             }
22              
23              
24 18     18 1 48 sub exists { 1 }
25              
26              
27 136     136 1 358 sub implied_scope { 'singleton' }
28              
29             __PACKAGE__->meta->make_immutable;
30              
31             __END__
32              
33             =pod
34              
35             =encoding UTF-8
36              
37             =head1 NAME
38              
39             Bolts::Blueprint::Literal - A blueprint that points to a literal value
40              
41             =head1 VERSION
42              
43             version 0.142930
44              
45             =head1 SYNOPSIS
46              
47             use Bolts;
48              
49             # The usual sugar
50             artifact thing1 => 42;
51             artifact thing2 => ( value => 42 );
52             artifact thing3 => (
53             value => [ 'this', 'is', 'an', 'example' ],
54             );
55              
56             # Or directly...
57             my $meta = Bolts::Bag->start_bag;
58              
59             my $artifact = Bolts::Artifact->new(
60             name => 'thing',
61             blueprint => $meta->locator->acquire('blueprint', 'literal', {
62             value => 42,
63             },
64             scope => $meta->locator->acquire('scope', '_'),
65             );
66              
67             =head1 DESCRIPTION
68              
69             Provides a blueprint that points to a single value. This is best used for scalars, strings, and numbers, but could be used for references.
70              
71             B<Caveat.> In the case of references, the same reference is returned every time so the contents of that reference might be modified by anyone that acquires it. This may be desirable in your application, but there's the warning in case it is not.
72              
73             =head1 ROLES
74              
75             =over
76              
77             =item *
78              
79             L<Bolts::Blueprint::Role::Injector>
80              
81             =back
82              
83             =head1 ATTRIBUTES
84              
85             =head2 value
86              
87             This is the literal value to return when this blueprint is resolved. This can be anything you can assign to a scalar variable, including references to arrays and hash (see the caveat above).
88              
89             =head1 METHODS
90              
91             =head2 builder
92              
93             Returns the L</value>.
94              
95             =head2 exists
96              
97             Always returns true.
98              
99             =head2 implied_scope
100              
101             This is set. A literal blueprint value acts like a global singleton.
102              
103             =head1 AUTHOR
104              
105             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2014 by Qubling Software LLC.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =cut