| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::Iron::IronCache::Item; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | ## no critic (Documentation::RequirePodAtEnd) | 
| 4 |  |  |  |  |  |  | ## no critic (Documentation::RequirePodSections) | 
| 5 |  |  |  |  |  |  | ## no critic (Subroutines::RequireArgUnpacking) | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 7934 | use 5.010_000; | 
|  | 3 |  |  |  |  | 13 |  | 
| 8 | 3 |  |  | 3 |  | 18 | use strict; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 61 |  | 
| 9 | 3 |  |  | 3 |  | 15 | use warnings; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 68 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # Global creator | 
| 12 |  |  |  | 3 |  |  | BEGIN { | 
| 13 |  |  |  |  |  |  | # No exports | 
| 14 |  |  |  |  |  |  | } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # Global destructor | 
| 17 |  |  |  | 3 |  |  | END { | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | # ABSTRACT: IronCache (Online Item-Value Storage) Client (Cache Item). | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | our $VERSION = '0.13'; # VERSION: generated by DZP::OurPkgVersion | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 3 |  |  | 3 |  | 19 | use Log::Any  qw($log); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 16 |  | 
| 28 | 3 |  |  | 3 |  | 667 | use Hash::Util 0.06 qw{lock_keys unlock_keys}; | 
|  | 3 |  |  |  |  | 46 |  | 
|  | 3 |  |  |  |  | 18 |  | 
| 29 | 3 |  |  | 3 |  | 195 | use Carp::Assert::More; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 470 |  | 
| 30 | 3 |  |  | 3 |  | 22 | use English '-no_match_vars'; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 18 |  | 
| 31 | 3 |  |  | 3 |  | 1167 | use Params::Validate qw(:all); | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 2027 |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # CONSTANTS for this module | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # DEFAULTS | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub new { | 
| 39 | 1 |  |  | 1 | 1 | 519 | my $class = shift; | 
| 40 | 1 |  |  |  |  | 61 | my %params = validate( | 
| 41 |  |  |  |  |  |  | @_, { | 
| 42 |  |  |  |  |  |  | 'value' => { type => SCALAR, },        # Item value (free text), mandatory, can be empty. | 
| 43 |  |  |  |  |  |  | 'expires_in' => { type => SCALAR, optional => 1, },   # How long in seconds to keep the item in the cache before it is deleted. | 
| 44 |  |  |  |  |  |  | 'expires' => { type => SCALAR, optional => 1, },      # When will the item be deleted. This is a date string. | 
| 45 |  |  |  |  |  |  | # TODO Add expires into docs! | 
| 46 |  |  |  |  |  |  | 'replace' => { type => SCALAR, optional => 1, },      # Only set the item if the item is already in the cache. | 
| 47 |  |  |  |  |  |  | 'add' => { type => SCALAR, optional => 1, },          # Only set the item if the item is not already in the cache. | 
| 48 |  |  |  |  |  |  | 'cas' => { type => SCALAR, optional => 1, },          # Cas value can only be set when the item is read from the cache. | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | ); | 
| 51 | 1 |  |  |  |  | 12 | $log->tracef('Entering new(%s, %s)', $class, %params); | 
| 52 | 1 |  |  |  |  | 98 | my $self; | 
| 53 | 1 |  |  |  |  | 5 | my @self_keys = ( ## no critic (CodeLayout::ProhibitQuotedWordLists) | 
| 54 |  |  |  |  |  |  | 'value',        # Item value (free text), can be empty. | 
| 55 |  |  |  |  |  |  | 'expires_in',   # How long in seconds to keep the item in the cache before it is deleted. | 
| 56 |  |  |  |  |  |  | 'expires',      # When will the item be deleted. This is a date string. | 
| 57 |  |  |  |  |  |  | 'replace',      # Only set the item if the item is already in the cache. | 
| 58 |  |  |  |  |  |  | 'add',          # Only set the item if the item is not already in the cache. | 
| 59 |  |  |  |  |  |  | 'cas',          # Cas value can only be set when the item is read from the cache. | 
| 60 |  |  |  |  |  |  | ); | 
| 61 | 1 |  |  |  |  | 1 | lock_keys(%{$self}, @self_keys); | 
|  | 1 |  |  |  |  | 15 |  | 
| 62 | 1 | 50 |  |  |  | 63 | $self->{'value'} = defined $params{'value'} ? $params{'value'} : undef; | 
| 63 | 1 | 50 |  |  |  | 4 | $self->{'expires_in'} = defined $params{'expires_in'} ? $params{'expires_in'} : undef; | 
| 64 | 1 | 50 |  |  |  | 4 | $self->{'expires'} = defined $params{'expires'} ? $params{'expires'} : undef; | 
| 65 | 1 | 50 |  |  |  | 4 | $self->{'replace'} = defined $params{'replace'} ? $params{'replace'} : undef; | 
| 66 | 1 | 50 |  |  |  | 4 | $self->{'add'} = defined $params{'add'} ? $params{'add'} : undef; | 
| 67 | 1 | 50 |  |  |  | 4 | $self->{'cas'} = defined $params{'cas'} ? $params{'cas'} : undef; | 
| 68 |  |  |  |  |  |  | # All of the above can be undefined, except the value. | 
| 69 | 1 |  |  |  |  | 15 | assert_defined( $self->{'value'}, 'self->{value} is defined and is not blank.' ); | 
| 70 |  |  |  |  |  |  | # If timeout, add or expires_in are undefined, the IronMQ defaults (at the server) will be used. | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 1 |  |  |  |  | 6 | unlock_keys(%{$self}); | 
|  | 1 |  |  |  |  | 4 |  | 
| 73 | 1 |  |  |  |  | 10 | my $blessed_ref = bless $self, $class; | 
| 74 | 1 |  |  |  |  | 3 | lock_keys(%{$self}, @self_keys); | 
|  | 1 |  |  |  |  | 9 |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 1 |  |  |  |  | 74 | $log->tracef('Exiting new: %s', $blessed_ref); | 
| 77 | 1 |  |  |  |  | 293 | return $blessed_ref; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 |  |  | 0 | 1 |  | sub value { return $_[0]->_access_internal('value', $_[1]); } | 
| 82 | 0 |  |  | 0 | 1 |  | sub expires_in { return $_[0]->_access_internal('expires_in', $_[1]); } | 
| 83 | 0 |  |  | 0 | 1 |  | sub expires { return $_[0]->_access_internal('expires', $_[1]); } | 
| 84 | 0 |  |  | 0 | 1 |  | sub replace { return $_[0]->_access_internal('replace', $_[1]); } | 
| 85 | 0 |  |  | 0 | 1 |  | sub add { return $_[0]->_access_internal('add', $_[1]); } | 
| 86 | 0 |  |  | 0 | 1 |  | sub cas { return $_[0]->_access_internal('cas', $_[1]); } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | # TODO Move _access_internal() to IO::Iron::Common. | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub _access_internal { | 
| 91 | 0 |  |  | 0 |  |  | my ($self, $var_name, $var_value) = @_; | 
| 92 | 0 |  |  |  |  |  | $log->tracef('_access_internal(%s, %s)', $var_name, $var_value); | 
| 93 | 0 | 0 |  |  |  |  | if( defined $var_value ) { | 
| 94 | 0 |  |  |  |  |  | $self->{$var_name} = $var_value; | 
| 95 | 0 |  |  |  |  |  | return $self; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  | else { | 
| 98 | 0 |  |  |  |  |  | return $self->{$var_name}; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | 1; | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | __END__ |