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   56 use 5.010_000;
  3         10  
8 3     3   39 use strict;
  3         16  
  3         90  
9 3     3   17 use warnings;
  3         5  
  3         71  
10              
11             # Global creator
12       3     BEGIN {
13             }
14              
15             # Global destructor
16       3     END {
17             }
18              
19             # ABSTRACT: IronMQ (Online Message Queue) Client (Message).
20              
21             our $VERSION = '0.14'; # VERSION: generated by DZP::OurPkgVersion
22              
23 3     3   21 use Log::Any qw($log);
  3         15  
  3         35  
24 3     3   614 use Hash::Util 0.06 qw{lock_keys unlock_keys};
  3         60  
  3         16  
25 3     3   221 use Carp::Assert::More;
  3         10  
  3         649  
26 3     3   23 use English '-no_match_vars';
  3         6  
  3         24  
27 3     3   1118 use Params::Validate qw(:all);
  3         6  
  3         2085  
28              
29             # CONSTANTS for this module
30              
31             # DEFAULTS
32              
33             sub new {
34 0     0 1   my $class = shift;
35 0           my %params = validate(
36             @_,
37             {
38             'body' => { type => SCALAR, }, # Message body (free text), can be empty.
39             'delay' => { type => SCALAR, optional => 1, }
40             , # The item will not be available on the queue until this many seconds have passed.
41             'push_headers' => { type => HASHREF, optional => 1, }, # Headers for push queues.
42             'id' => { type => SCALAR, optional => 1, }, # Message id from IronMQ queue (after message has been reserved/peeked).
43             'reserved_count' => { type => SCALAR, optional => 1, }, # FIXME item reserved_count
44             'reservation_id' => { type => SCALAR, optional => 1, }, # Reservation id string from the queue.
45             }
46             );
47 0           $log->tracef( 'Entering new(%s, %s)', $class, %params );
48 0           my $self;
49 0           my @self_keys = ( ## no critic (CodeLayout::ProhibitQuotedWordLists)
50             'body', # Message body (free text), can be empty.
51             'delay', # The item will not be available on the queue until this many seconds have passed.
52             'push_headers', # Push queue headers.
53             'id', # Message id from IronMQ queue (after message has been pulled/peeked).
54             'reserved_count', # FIXME item reserved_count
55             'reservation_id', # reservation_id
56             );
57 0           lock_keys( %{$self}, @self_keys );
  0            
58 0           $self->{'body'} = $params{'body'};
59 0 0         $self->{'delay'} = defined $params{'delay'} ? $params{'delay'} : undef;
60 0 0         $self->{'push_headers'} = defined $params{'push_headers'} ? $params{'push_headers'} : undef;
61 0 0         $self->{'id'} = defined $params{'id'} ? $params{'id'} : undef;
62 0 0         $self->{'reserved_count'} = defined $params{'reserved_count'} ? $params{'reserved_count'} : undef;
63 0 0         $self->{'reservation_id'} = defined $params{'reservation_id'} ? $params{'reservation_id'} : undef;
64              
65             # All of the above can be undefined, except the body: the message can not be empty.
66             # If delay is undefined, the IronMQ defaults (at the server) will be used.
67              
68 0           unlock_keys( %{$self} );
  0            
69 0           my $blessed_ref = bless $self, $class;
70 0           lock_keys( %{$self}, @self_keys );
  0            
71              
72 0           $log->tracef( 'Exiting new: %s', $blessed_ref );
73 0           return $blessed_ref;
74             }
75              
76 0     0 1   sub body { return $_[0]->_access_internal( 'body', $_[1] ); }
77 0     0 1   sub delay { return $_[0]->_access_internal( 'delay', $_[1] ); }
78 0     0 1   sub push_headers { return $_[0]->_access_internal( 'push_headers', $_[1] ); }
79 0     0 1   sub id { return $_[0]->_access_internal( 'id', $_[1] ); }
80 0     0 1   sub reserved_count { return $_[0]->_access_internal( 'reserved_count', $_[1] ); }
81 0     0 1   sub reservation_id { return $_[0]->_access_internal( 'reservation_id', $_[1] ); }
82              
83             # TODO Move _access_internal() to IO::Iron::Common.
84              
85             sub _access_internal {
86 0     0     my ( $self, $var_name, $var_value ) = @_;
87 0           $log->tracef( '_access_internal(%s, %s)', $var_name, $var_value );
88 0 0         if ( defined $var_value ) {
89 0           $self->{$var_name} = $var_value;
90 0           return $self;
91             }
92             else {
93 0           return $self->{$var_name};
94             }
95             }
96              
97             1;
98              
99             __END__
100              
101             =pod
102              
103             =encoding UTF-8
104              
105             =head1 NAME
106              
107             IO::Iron::IronMQ::Message - IronMQ (Online Message Queue) Client (Message).
108              
109             =head1 VERSION
110              
111             version 0.14
112              
113             =head1 SYNOPSIS
114              
115             Please see IO::Iron::IronMQ::Client for usage.
116              
117             =for stopwords IronMQ UNDEF Mikko Koivunalho perldoc CPAN AnnoCPAN tradename
118              
119             =for stopwords licensable MERCHANTABILITY
120              
121             =head1 REQUIREMENTS
122              
123             =head1 SUBROUTINES/METHODS
124              
125             =head2 new
126              
127             Creator function.
128             UNDEF values not accepted.
129             body is mandatory; delay and push_headers are optional.
130             id, reserved_count and reservation_id are for internal use.
131              
132             =head2 Getters/setters
133              
134             Set or get a property.
135             When setting, returns the reference to the object.
136              
137             =over 8
138              
139             =item body Message body (free text), can be empty.
140              
141             =item delay The item will not be available on the queue until this many seconds have passed.
142              
143             =item push_headers Push queue HTTP headers.
144              
145             =item id Message id from IronMQ queue (after message has been pulled/peeked).
146              
147             =item reserved_count Item reserved count.
148              
149             =item reservation_id Reservation id string from the queue.
150              
151             =back
152              
153             =head1 AUTHOR
154              
155             Mikko Koivunalho <mikko.koivunalho@iki.fi>
156              
157             =head1 BUGS
158              
159             Please report any bugs or feature requests to bug-io-iron@rt.cpan.org or through the web interface at:
160             http://rt.cpan.org/Public/Dist/Display.html?Name=IO-Iron
161              
162             =head1 COPYRIGHT AND LICENSE
163              
164             This software is copyright (c) 2023 by Mikko Koivunalho.
165              
166             This is free software; you can redistribute it and/or modify it under
167             the same terms as the Perl 5 programming language system itself.
168              
169             The full text of the license can be found in the
170             F<LICENSE> file included with this distribution.
171              
172             =cut