File Coverage

blib/lib/IO/Iron/IronMQ/Message.pm
Criterion Covered Total %
statement 23 55 41.8
branch 0 12 0.0
condition n/a
subroutine 10 18 55.5
pod 7 7 100.0
total 40 92 43.4


line stmt bran cond sub pod time code
1             package IO::Iron::IronMQ::Message;
2              
3             ## no critic (Documentation::RequirePodAtEnd)
4             ## no critic (Documentation::RequirePodSections)
5             ## no critic (Subroutines::RequireArgUnpacking)
6              
7 3     3   52 use 5.010_000;
  3         9  
8 3     3   37 use strict;
  3         8  
  3         89  
9 3     3   16 use warnings;
  3         5  
  3         70  
10              
11             # Global creator
12       3     BEGIN {
13             }
14              
15             # Global destructor
16       3     END {
17             }
18              
19              
20             # ABSTRACT: IronMQ (Online Message Queue) Client (Message).
21              
22             our $VERSION = '0.12_01'; # TRIAL VERSION: generated by DZP::OurPkgVersion
23              
24              
25              
26 3     3   17 use Log::Any qw($log);
  3         6  
  3         16  
27 3     3   690 use Hash::Util 0.06 qw{lock_keys unlock_keys};
  3         47  
  3         16  
28 3     3   196 use Carp::Assert::More;
  3         8  
  3         459  
29 3     3   19 use English '-no_match_vars';
  3         7  
  3         16  
30 3     3   1173 use Params::Validate qw(:all);
  3         15  
  3         1998  
31              
32             # CONSTANTS for this module
33              
34             # DEFAULTS
35              
36              
37             sub new {
38 0     0 1   my $class = shift;
39 0           my %params = validate(
40             @_, {
41             'body' => { type => SCALAR, }, # Message body (free text), can be empty.
42             'delay' => { type => SCALAR, optional => 1, }, # The item will not be available on the queue until this many seconds have passed.
43             'push_headers' => { type => HASHREF, optional => 1, }, # Headers for push queues.
44             'id' => { type => SCALAR, optional => 1, }, # Message id from IronMQ queue (after message has been reserved/peeked).
45             'reserved_count' => { type => SCALAR, optional => 1, }, # FIXME item reserved_count
46             'reservation_id' => { type => SCALAR, optional => 1, }, # Reservation id string from the queue.
47             }
48             );
49 0           $log->tracef('Entering new(%s, %s)', $class, %params);
50 0           my $self;
51 0           my @self_keys = ( ## no critic (CodeLayout::ProhibitQuotedWordLists)
52             'body', # Message body (free text), can be empty.
53             'delay', # The item will not be available on the queue until this many seconds have passed.
54             'push_headers', # Push queue headers.
55             'id', # Message id from IronMQ queue (after message has been pulled/peeked).
56             'reserved_count', # FIXME item reserved_count
57             'reservation_id', # reservation_id
58             );
59 0           lock_keys(%{$self}, @self_keys);
  0            
60 0           $self->{'body'} = $params{'body'};
61 0 0         $self->{'delay'} = defined $params{'delay'} ? $params{'delay'} : undef;
62 0 0         $self->{'push_headers'} = defined $params{'push_headers'} ? $params{'push_headers'} : undef;
63 0 0         $self->{'id'} = defined $params{'id'} ? $params{'id'} : undef;
64 0 0         $self->{'reserved_count'} = defined $params{'reserved_count'} ? $params{'reserved_count'} : undef;
65 0 0         $self->{'reservation_id'} = defined $params{'reservation_id'} ? $params{'reservation_id'} : undef;
66             # All of the above can be undefined, except the body: the message can not be empty.
67             # If delay is undefined, the IronMQ defaults (at the server) will be used.
68              
69 0           unlock_keys(%{$self});
  0            
70 0           my $blessed_ref = bless $self, $class;
71 0           lock_keys(%{$self}, @self_keys);
  0            
72              
73 0           $log->tracef('Exiting new: %s', $blessed_ref);
74 0           return $blessed_ref;
75             }
76              
77              
78 0     0 1   sub body { return $_[0]->_access_internal('body', $_[1]); }
79 0     0 1   sub delay { return $_[0]->_access_internal('delay', $_[1]); }
80 0     0 1   sub push_headers { return $_[0]->_access_internal('push_headers', $_[1]); }
81 0     0 1   sub id { return $_[0]->_access_internal('id', $_[1]); }
82 0     0 1   sub reserved_count { return $_[0]->_access_internal('reserved_count', $_[1]); }
83 0     0 1   sub reservation_id { return $_[0]->_access_internal('reservation_id', $_[1]); }
84              
85             # TODO Move _access_internal() to IO::Iron::Common.
86              
87             sub _access_internal {
88 0     0     my ($self, $var_name, $var_value) = @_;
89 0           $log->tracef('_access_internal(%s, %s)', $var_name, $var_value);
90 0 0         if( defined $var_value ) {
91 0           $self->{$var_name} = $var_value;
92 0           return $self;
93             }
94             else {
95 0           return $self->{$var_name};
96             }
97             }
98              
99             1;
100              
101             __END__