File Coverage

blib/lib/IO/Iron.pm
Criterion Covered Total %
statement 14 20 70.0
branch n/a
condition n/a
subroutine 6 9 66.6
pod 3 3 100.0
total 23 32 71.8


line stmt bran cond sub pod time code
1             package IO::Iron;
2              
3             ## no critic (Documentation::RequirePodAtEnd)
4             ## no critic (Documentation::RequirePodSections)
5              
6 3     3   105262 use 5.010_000;
  3         27  
7 3     3   55 use strict;
  3         6  
  3         76  
8 3     3   17 use warnings;
  3         6  
  3         101  
9              
10             # Global creator
11             BEGIN {
12 3     3   452 use parent qw( Exporter );
  3         307  
  3         15  
13 3     3   287 our ( @EXPORT_OK, %EXPORT_TAGS );
14 3         11 %EXPORT_TAGS = ( 'all' => [qw(ironcache ironmq ironworker)] );
15 3         632 @EXPORT_OK = qw(all ironcache ironmq ironworker);
16             }
17             our @EXPORT_OK;
18              
19             # Global destructor
20       3     END {
21             }
22              
23             # ABSTRACT: Client Libraries to Iron services IronCache, IronMQ and IronWorker.
24              
25             our $VERSION = '0.14'; # VERSION: generated by DZP::OurPkgVersion
26              
27             require IO::Iron::IronCache::Client;
28             require IO::Iron::IronMQ::Client;
29             require IO::Iron::IronWorker::Client;
30              
31             sub ironcache {
32 0     0 1   my (%params) = @_;
33 0           return IO::Iron::IronCache::Client->new( \%params );
34             }
35              
36             sub ironmq {
37 0     0 1   my (%params) = @_;
38 0           return IO::Iron::IronMQ::Client->new( \%params );
39             }
40              
41             sub ironworker {
42 0     0 1   my (%params) = @_;
43 0           return IO::Iron::IronWorker::Client->new(%params);
44             }
45              
46             1;
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             IO::Iron - Client Libraries to Iron services IronCache, IronMQ and IronWorker.
57              
58             =head1 VERSION
59              
60             version 0.14
61              
62             =head1 SYNOPSIS
63              
64             use IO::Iron;
65             use IO::Iron qw{ironcache ironmq ironworker};
66             use IO::Iron ':all';
67              
68             my $iron_mq_client = ironmq();
69             my @iron_mq_queues = $iron_mq_client->get_queues();
70              
71             my $iron_cache_client = ironcache( config => 'iron_cache.json' );
72             my @iron_caches = $iron_cache_client->get_caches();
73              
74             my $iron_worker_client = ironworker( config => 'iron_worker.json' );
75             my @iron_codes = $iron_worker_client->list_code_packages();
76              
77             =head1 DESCRIPTION
78              
79             IronCache, IronMQ and IronWorker are cloud based services accessible
80             via a REST API. CPAN Distribution IO::Iron contains Perl clients for
81             accessing them.
82              
83             [See L<http://www.iron.io/|http://www.iron.io/>]
84              
85             Please see the individual clients for further documentation and usage.
86              
87             Clients:
88              
89             =over 8
90              
91             =item L<IO::Iron::IronCache::Client|IO::Iron::IronCache::Client>
92              
93             =item L<IO::Iron::IronMQ::Client|IO::Iron::IronMQ::Client>
94              
95             =item L<IO::Iron::IronWorker::Client|IO::Iron::IronWorker::Client>
96              
97             =back
98              
99             IO-Iron code is available at Github: L<IO-Iron|https://github.com/mikkoi/io-iron>
100             for download with Git: L<https://github.com/mikkoi/io-iron.git|https://github.com/mikkoi/io-iron.git>.
101              
102             =head2 IO::Iron
103              
104             Package IO::Iron is only a "convenience" module for quick startup.
105             The three functions provided are L</ironcache>, L</ironmq> and L</ironworker>.
106              
107             The following parameters can be given to each of them as hash item type
108             parameters. See section L</SYNOPSIS> for an example.
109              
110             =over 8
111              
112             =item C<project_id>, The ID of the project to use for requests.
113              
114             =item C<token>, The OAuth token that is used to authenticate requests.
115              
116             =item C<host>, The domain name the API can be located at. E.g. 'mq-aws-us-east-1.iron.io/1'.
117              
118             =item C<protocol>, The protocol that will be used to communicate with the API. Defaults to "https".
119              
120             =item C<port>, The port to connect to the API through. Defaults to 443.
121              
122             =item C<api_version>, The version of the API to connect through. Defaults to the version supported by the client.
123              
124             =item C<timeout>, REST client timeout (for REST calls accessing IronMQ.)
125              
126             =item C<config>, Config filename with path if required.
127              
128             =back
129              
130             You can also give the parameters in the config file F<.iron.json> or
131             F<iron.json> (in local directory) or as environmental variables. Please read
132             L<Configuring the Official Client Libraries|http://dev.iron.io/mq/reference/configuration/> for further details.
133              
134             =head3 Client Documentation
135              
136             Please read individual client's documentation for using them.
137              
138             =head3 Exceptions
139              
140             A REST call to Iron service may fail for several reason.
141             All failures generate an exception using the L<Exception::Class|Exception::Class> package.
142             Class IronHTTPCallException contains the field status_code, response_message and error.
143             Error is formatted as such: IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>.
144              
145             use Try::Tiny;
146             use Scalar::Util qw{blessed};
147             try {
148             my $asked_iron_cache_01 = $iron_cache_client->get_cache('name' => 'unique_cache_name_01');
149             }
150             catch {
151             die $_ unless blessed $_ && $_->can('rethrow');
152             if ( $_->isa('IronHTTPCallException') ) {
153             if ($_->status_code == 404) {
154             print "Bad things! Can not just find the catch in this!\n";
155             }
156             }
157             else {
158             $_->rethrow; # Push the error upwards.
159             }
160             };
161              
162             When using policies (see next chapter) also exceptions
163             NoIronPolicyException and CharacterGroupNotDefinedIronPolicyException
164             can be met.
165              
166             =head3 Policies
167              
168             Policies is a way to limit the names of message queues, code packages,
169             caches and items (item keys)
170             to a predefined group of possible strings. This can limit the chances
171             for typos and enforce an enterprise policy. The policies are loaded from
172             a JSON file which is specified either when creating a
173             IO::Iron::Iron*::Client object, or
174             in the config file F<.iron.json> (or equivalent).
175              
176             =head4 Policies in Config file
177              
178             Add the item I<policies> to the config file. The value of the item is the
179             filename of the policies file.
180              
181             Example config file:
182              
183             {
184             "project_id":"51bdf5fb2267d84ced002c99",
185             "token":"-Q9OEHZPhdZtd0KHBzzdUJIqV_E",
186             "host":"cache-aws-us-east-1.iron.io",
187             "policies":"iron_policies.json"
188             }
189              
190             =head4 Policies file specified when creating the client
191              
192             my $policies_filename = '/etc/ironmq/global_policies.json';
193             my $client = IO::Iron::IronCache::Client->new('policies' => $policies_filename);
194              
195             =head4 Examples of Policies File and Explanation of Configuration
196              
197             The 'default' policies JSON file:
198              
199             {
200             "definition":{
201             "character_group":{
202             },
203             "no_limitation":1, # There is an unlimited number of alternatives.
204             },
205             "queue":{ "name":[ "[:alnum:]{1,}" ], },
206             "cache":{
207             "name":[ "[:alnum:]{1,}" ],
208             "item_key":[ "[:alnum:]{1,}" ]
209             },
210             "worker":{ "name":[ "[:alnum:]{1,}" ], }
211             }
212              
213             The above file would set an open policy for IronMQ, IronCache and IronWorker alike.
214             The file is divided into four parts: definition for defining meta options, and
215             queue|cache|worker parts for defining the changing strings
216             (queue|cache|worker names and item keys). The character group I<alnum> covers
217             all ascii alphabetic characters (both lower and upper case) and digits (0-9).
218              
219             N.B. The option I<definition:no_limitation> controls the open/closed policy.
220             If I<definition:no_limitation> is set (1=set), the policy control is
221             turned off.
222              
223             An example of policies file
224              
225             {
226             "__comment1":"Use normal regexp. [:digit:] = number:0-9, [:alpha:] = alphabetic character, [:alnum:] = character or number.",
227             "__comment2":"Do not use end/begin limitators '^' and '\$'. They are added automatically.",
228             "__comment3":"Note that character groups are closed inside '[::]', not '[[:]]' as normal POSIX groups.",
229             "definition":{
230             "character_group":{
231             "[:lim_uchar:]":"ABC",
232             "[:low_digit:]":"0123"
233             },
234             },
235             "cache":{
236             "name":[
237             "cache_01_main",
238             "cache_[:alpha:]{1}[:digit:]{2}"
239             ],
240             "item_key":[
241             "item.01_[:digit:]{2}",
242             "item.02_[:lim_uchar:]{1,2}"
243             ]
244             }
245             }
246              
247             This policies file sets policies for cache names and item keys. Both have two
248             templates. Template "cache_01_main" is without wildcards: the template list
249             can also only contain predefined names or keys. Sometimes this could be
250             exactly the wanted behaviour, especially in regard to cache and
251             message queue names.
252              
253             Items beginning with '__' are considered comments. Comments can not be
254             inserted into lists, such as I<character_group>.
255              
256             The I<definition> part contains the list I<character_group> for user-defined
257             groups. The following groups are predefined:
258              
259             =over 8
260              
261             =item [:alpha:], ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
262              
263             =item [:alnum:], ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
264              
265             =item [:digit:], 0123456789
266              
267             =item [:lower:], abcdefghijklmnopqrstuvwxyz
268              
269             =item [:upper:], ABCDEFGHIJKLMNOPQRSTUVWXYZ
270              
271             =item [:word:], ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_
272              
273             =back
274              
275             All lower ASCII (7-bit) characters are allowed in names and in character
276             groups, except for the reserved characters (S<RFC 3986>)
277             S<B<!$&'()*+,;=:/?#[]@>>.
278              
279             A character group definition is closed inside characters '[::]',
280             not '[[:]]' as normal POSIX groups. Only the equivalents of the POSIX groups
281             mentioned above can be used; e.g. POSIX group C<[[:graph:]]> is not available.
282              
283             When using the character groups in a name or key, only two markings are allowed:
284             C<[:group:]{n}> and C<[:group:]{n,n}>, where C<n> is an integer.
285             This limitation (not being able to use any regular expression) is due to the
286             double functionality of the policy: a) it acts as a filter when creating
287             and naming new message queues, code packages, caches and cache items; 2) it
288             can be used to list all possible names, for example when querying for
289             cache items.
290              
291             =for stopwords IronCache IronMQ IronWorker Iron.io API JSON IronIO json OAuth
292             aws AWS Rackspace CPAN Github startup ironcache ironmq ironworker https Config
293             filename config IronHTTPCallException NoIronPolicyException
294             CharacterGroupNotDefinedIronPolicyException alnum ascii wildcards behaviour
295             abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ POSIX Subdirectory lv
296             Mikko Koivunalho perldoc AnnoCPAN webhooks tradename licensable MERCHANTABILITY
297              
298             =head1 STATUS
299              
300             Iron.io libraries are currently being developed so changes in the API are
301             possible.
302              
303             =head1 REQUIREMENTS
304              
305             IO::Iron requires an IronIO account. Three configuration items must
306             be set (others available) before using the functions:
307             C<project_id>, C<token> and C<host>. These can be set in a json file,
308             as environmental variables or as parameters when creating the object.
309              
310             =over 8
311              
312             =item C<project_id>, the identification string, from IronIO.
313              
314             =item C<token>, an OAuth authentication token string, from IronIO.
315              
316             =item C<host>, the cloud in which you want to operate, e.g. 'cache-aws-us-east-1' for AWS (Amazon) or 'mq-rackspace-ord.iron.io' or 'mq-rackspace-lon.iron.io' for Rackspace.
317              
318             Please see L<IronMQ HTTP API Reference (hosts)|http://dev.iron.io/mq/3/host/>
319             for available hosts.
320              
321             =back
322              
323             =head1 TESTING
324              
325             Subdirectory F<integ_t> contains "integration" tests which require an active Iron.io account and Internet connection.
326             To run the tests, create first three config files in the main directory:
327             F<iron_cache.json>, F<iron_mq.json>, F<iron_worker.json>.
328             Set at least the following attributes: B<project_id>, B<token> and B<host>.
329              
330             Execute B<prove> (L<prove|https://metacpan.org/pod/distribution/TAP-Parser/bin/prove>), e.g. B<prove -lv -Iinteg_t integ_t\Iron\iron_all.t>.
331              
332             =head1 FUNCTIONS
333              
334             =head2 ironcache
335              
336             Create an IronCache client object and return it to user.
337              
338             =head2 ironmq
339              
340             Create an IronMQ client object and return it to user.
341              
342             =head2 ironworker
343              
344             Create an IronWorker client object and return it to user.
345              
346             =head1 AUTHOR
347              
348             Mikko Koivunalho <mikko.koivunalho@iki.fi>
349              
350             =head1 BUGS
351              
352             Please report any bugs or feature requests to bug-io-iron@rt.cpan.org or through the web interface at:
353             http://rt.cpan.org/Public/Dist/Display.html?Name=IO-Iron
354              
355             =head1 COPYRIGHT AND LICENSE
356              
357             This software is copyright (c) 2023 by Mikko Koivunalho.
358              
359             This is free software; you can redistribute it and/or modify it under
360             the same terms as the Perl 5 programming language system itself.
361              
362             The full text of the license can be found in the
363             F<LICENSE> file included with this distribution.
364              
365             =cut