File Coverage

blib/lib/Juju/Util.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package Juju::Util;
2             BEGIN {
3 1     1   634 $Juju::Util::AUTHORITY = 'cpan:ADAMJS';
4             }
5             $Juju::Util::VERSION = '2.001_1';
6             # ABSTRACT: helper methods for Juju
7              
8              
9 1     1   182 use Moose;
  0            
  0            
10             use HTTP::Tiny;
11             use JSON::PP;
12             use Function::Parameters;
13             use namespace::autoclean;
14              
15              
16             method query_cs(Str $charm, Str $series = "trusty") {
17             my $cs_url = 'https://manage.jujucharms.com/api/3/charm';
18              
19             my $composed_url = sprintf("%s/%s/%s", $cs_url, $series, $charm);
20             my $res = HTTP::Tiny->new->get($composed_url);
21             die "Unable to query charm store: ".$res->{reason} unless $res->{success};
22             return decode_json($res->{content});
23             }
24              
25             __PACKAGE__->meta->make_immutable;
26             1;
27              
28             __END__
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             Juju::Util - helper methods for Juju
37              
38             =head1 VERSION
39              
40             version 2.001_1
41              
42             =head1 SYNOPSIS
43              
44             use Juju::Util;
45             my $util = Juju::Util->new;
46             my $charm = $util->query_cs('wordpress', 'precise');
47              
48             =head1 METHODS
49              
50             =head2 query_cs
51              
52             helper for querying charm store for charm details
53              
54             B<Params>
55              
56             =over 4
57              
58             =item *
59              
60             C<charm>
61              
62             name of charm to query
63              
64             =item *
65              
66             C<series>
67              
68             (optional) series to limit to (defaults: trusty)
69              
70             =back
71              
72             =head1 AUTHOR
73              
74             Adam Stokes <adamjs@cpan.org>
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             This software is Copyright (c) 2014 by Adam Stokes.
79              
80             This is free software, licensed under:
81              
82             The MIT (X11) License
83              
84             =head1 SEE ALSO
85              
86             Please see those modules/websites for more information related to this module.
87              
88             =over 4
89              
90             =item *
91              
92             L<Juju|Juju>
93              
94             =back
95              
96             =head1 DISCLAIMER OF WARRANTY
97              
98             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
99             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
100             WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
101             PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
102             EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
103             IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
104             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
105             SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
106             THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
107              
108             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
109             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
110             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
111             TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
112             CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
113             SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
114             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
115             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
116             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
117             DAMAGES.
118              
119             =cut