| 1 | package Time::Progress::Stored::Storage::Memory; | ||||||||||||
| 2 | 1 | $Time::Progress::Stored::Storage::Memory::VERSION = '1.002'; | |||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use true; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | extends "Time::Progress::Stored::Storage"; | |||||||||||
| 6 | |||||||||||||
| 7 | =head1 NAME | ||||||||||||
| 8 | |||||||||||||
| 9 | Time::Progress::Stored::Storage::Memory - Store the reports in-memory | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||
| 12 | |||||||||||||
| 13 | This is mostly for testing. | ||||||||||||
| 14 | |||||||||||||
| 15 | Store the reports in serialized JSON, to emulate storing them in an | ||||||||||||
| 16 | external server, which is better than just keeping the hashref around | ||||||||||||
| 17 | would be. | ||||||||||||
| 18 | |||||||||||||
| 19 | =cut | ||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | use JSON::Tiny qw/ encode_json decode_json /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | =head1 PROPERTIES | ||||||||||||
| 26 | |||||||||||||
| 27 | =cut | ||||||||||||
| 28 | |||||||||||||
| 29 | 1 | has id__report => ( is => "lazy" ); | |||||||||||
| 30 | 1 | ▶ | sub _build_id__report { +{} } | ||||||||||
|
Subroutine
_build_id__report: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | =head1 METHODS | ||||||||||||
| 35 | |||||||||||||
| 36 | =head2 store($id, $content) : Bool | ||||||||||||
| 37 | |||||||||||||
| 38 | Store the current report $content (a data structure) under the $id | ||||||||||||
| 39 | key. | ||||||||||||
| 40 | |||||||||||||
| 41 | =cut | ||||||||||||
| 42 | |||||||||||||
| 43 | 44 | ▶ | sub store { | ||||||||||
|
Subroutine
store: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | 44 | my $self = shift; | |||||||||||
| 45 | 44 | my ($id, $content) = @_; | |||||||||||
| 46 | 44 | $self->id__report->{ $id } = encode_json( $content ); | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | =head2 retrieve($id) : $content | undef | ||||||||||||
| 50 | |||||||||||||
| 51 | Retrieve the current report $content under the $id key, or undef if | ||||||||||||
| 52 | none was found. | ||||||||||||
| 53 | |||||||||||||
| 54 | =cut | ||||||||||||
| 55 | |||||||||||||
| 56 | 4 | ▶ | sub retrieve { | ||||||||||
|
Subroutine
retrieve: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 57 | 4 | my $self = shift; | |||||||||||
| 58 | 4 | my ($id) = @_; | |||||||||||
| 59 | 4 | ▶ | my $report_json = $self->id__report->{ $id } // return undef; | ||||||||||
|
Condition50%1/2
$self->id__report->{$id} // (return undef)
MC/DC0%0/1
$self->id__report->{$id} // (return undef)
$self->id__report->{$id}
Truth table50%1/2
A
A= $self->id__report->{$id}
| |||||||||||||
| 60 | 4 | return decode_json( $report_json ); | |||||||||||
| 61 | } | ||||||||||||