| 1 | package Bolts::Scope::Singleton; | ||||||||||
| 2 | 10 | $Bolts::Scope::Singleton::VERSION = '0.143170'; | |||||||||
| 3 | # ABSTRACT: For artifacts that are reused for the lifetime of the bag | ||||||||||
| 4 | |||||||||||
| 5 | 10 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 10 | ▶ | use Hash::Util::FieldHash 'fieldhash'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 10 | with 'Bolts::Scope'; | |||||||||
| 10 | |||||||||||
| 11 | 10 | fieldhash my %singleton; | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | sub get { | ||||||||||
| 15 | 61 | ▶ | my ($self, $bag, $name) = @_; | ||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | 61 | ▶ | return unless defined $singleton{$bag}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 52 | ▶ | return unless defined $singleton{$bag}{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 52 | return $singleton{$bag}{$name}; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | sub put { | ||||||||||
| 23 | 9 | ▶ | my ($self, $bag, $name, $artifact) = @_; | ||||||||
|
Subroutine
put: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 24 | |||||||||||
| 25 | 9 | ▶ | $singleton{$bag} = {} unless defined $singleton{$bag}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 9 | $singleton{$bag}{$name} = $artifact; | |||||||||
| 27 | 9 | return; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 10 | __PACKAGE__->meta->make_immutable; | |||||||||
| 31 | |||||||||||
| 32 | __END__ | ||||||||||
| 33 | |||||||||||
| 34 | =pod | ||||||||||
| 35 | |||||||||||
| 36 | =encoding UTF-8 | ||||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | Bolts::Scope::Singleton - For artifacts that are reused for the lifetime of the bag | ||||||||||
| 41 | |||||||||||
| 42 | =head1 VERSION | ||||||||||
| 43 | |||||||||||
| 44 | version 0.143170 | ||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | This scope does not define a true singleton, but a singleton for the lifetime of the bag it is associated with, which might be the same thing. | ||||||||||
| 49 | |||||||||||
| 50 | =head1 ROLES | ||||||||||
| 51 | |||||||||||
| 52 | =over | ||||||||||
| 53 | |||||||||||
| 54 | =item * | ||||||||||
| 55 | |||||||||||
| 56 | L<Bolts::Scope> | ||||||||||
| 57 | |||||||||||
| 58 | =back | ||||||||||
| 59 | |||||||||||
| 60 | =head1 METHODS | ||||||||||
| 61 | |||||||||||
| 62 | =head2 get | ||||||||||
| 63 | |||||||||||
| 64 | If the named artifact has ever been stored for this bag, it will be returned by this method. | ||||||||||
| 65 | |||||||||||
| 66 | =head2 put | ||||||||||
| 67 | |||||||||||
| 68 | Puts the named artifact into the singleton cache for the bag. Once there, it will stay there for as long as the object exists. | ||||||||||
| 69 | |||||||||||
| 70 | =head1 AUTHOR | ||||||||||
| 71 | |||||||||||
| 72 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||
| 73 | |||||||||||
| 74 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 75 | |||||||||||
| 76 | This software is copyright (c) 2014 by Qubling Software LLC. | ||||||||||
| 77 | |||||||||||
| 78 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 79 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 80 | |||||||||||
| 81 | =cut | ||||||||||