API/UserAgent.pm

filter: Statementstmt 68.5% 24 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 64.7% 33 / 51 CC 3 SCAR 9.8
CC
3
Cov
62%
get
6.0
post
6.0
__ANON__
1.1
CRAP 2.7
« API.pm ↑ Summary API/Exception.pm »
1 package Map::Tube::API::UserAgent;
2  
3 1 $Map::Tube::API::UserAgent::VERSION = '0.05';
4 1 $Map::Tube::API::UserAgent::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Map::Tube::API::UserAgent - Low-level HTTP request handler for Map::Tube::API.
9  
10 =head1 VERSION
11  
12 Version 0.05
13  
14 =cut
15  
16 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use HTTP::Request::Common qw(GET POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Map::Tube::API::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶has 'ua' => (is => 'rw', default => sub { LWP::UserAgent->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
27  
28 =head1 DESCRIPTION
29  
30 It provides common useragent library for Map::Tube::API services.
31  
32 =head1 METHODS
33  
34 =head2 get($url)
35  
36 It expects one parameter i.e. URL and returns the standard response. On error
37 throws exception of type L<Map::Tube::API::Exception>.
38  
39 =cut
40  
41 sub get {
42 0 ▶ my ($self, $url) = @_;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
43  
44 0 my $response = $self->ua->request(GET($url));
45  
46 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
47 0 Map::Tube::API::Exception->throw(
48 { code => $response->code, message => $response->content });
49 }
50  
51 0 return $response;
52 }
53  
54 =head2 post($url, $content)
55  
56 It expects two parameters i.e. URL and Content in the same order and returns the
57 standard response.On error throws exception of type L<Map::Tube::API::Exception>.
58  
59 =cut
60  
61 sub post {
62 0 ▶ my ($self, $url, $content) = @_;
Subroutine post: not called CC=2 SCAR=17.9
Pod documented
63  
64 0 my $response = $self->ua->request(POST($url, $content));
65  
66 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
67 0 Map::Tube::API::Exception->throw(
68 { code => $response->code, message => $response->content });
69 }
70  
71 0 return $response;
72 }
73  
74 =head1 AUTHOR
75  
76 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
77  
78 =head1 REPOSITORY
79  
80 L<https://github.com/manwar/Map-Tube-API>
81  
82 =head1 BUGS
83  
84 Please report any bugs or feature requests to C<bug-map-tube-api at rt.cpan.org>,
85 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Map-Tube-API>.
86 I will be notified, and then you'll automatically be notified of progress on your
87 bug as I make changes.
88  
89 =head1 SUPPORT
90  
91 You can find documentation for this module with the perldoc command.
92  
93 perldoc Map::Tube::API::UserAgent
94  
95 You can also look for information at:
96  
97 =over 4
98  
99 =item * RT: CPAN's request tracker (report bugs here)
100  
101 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Map-Tube-API>
102  
103 =item * AnnoCPAN: Annotated CPAN documentation
104  
105 L<http://annocpan.org/dist/Map-Tube-API>
106  
107 =item * CPAN Ratings
108  
109 L<http://cpanratings.perl.org/d/Map-Tube-API>
110  
111 =item * Search CPAN
112  
113 L<http://search.cpan.org/dist/Map-Tube-API/>
114  
115 =back
116  
117 =head1 LICENSE AND COPYRIGHT
118  
119 Copyright (C) 2017 Mohammad S Anwar.
120  
121 This program is free software; you can redistribute it and/or modify it under
122 the terms of the the Artistic License (2.0). You may obtain a copy of the full
123 license at:
124  
125 L<http://www.perlfoundation.org/artistic_license_2_0>
126  
127 Any use, modification, and distribution of the Standard or Modified Versions is
128 governed by this Artistic License.By using, modifying or distributing the Package,
129 you accept this license. Do not use, modify, or distribute the Package, if you do
130 not accept this license.
131  
132 If your Modified Version has been derived from a Modified Version made by someone
133 other than you,you are nevertheless required to ensure that your Modified Version
134 complies with the requirements of this license.
135  
136 This license does not grant you the right to use any trademark, service mark,
137 tradename, or logo of the Copyright Holder.
138  
139 This license includes the non-exclusive, worldwide, free-of-charge patent license
140 to make, have made, use, offer to sell, sell, import and otherwise transfer the
141 Package with respect to any patent claims licensable by the Copyright Holder that
142 are necessarily infringed by the Package. If you institute patent litigation
143 (including a cross-claim or counterclaim) against any party alleging that the
144 Package constitutes direct or contributory patent infringement,then this Artistic
145 License to you shall terminate on the date that such litigation is filed.
146  
147 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
148 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
149 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
150 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
151 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
152 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
153 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154  
155 =cut
156  
157 1 1; # End of Map::Tube::API::UserAgent
« API.pm ↑ Summary API/Exception.pm »