| 1 | package URL::Social::BASE; | ||||||||||||||||||||
| 2 | 6 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 6 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | URL::Social::BASE - Base class for the different social classes. | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | You don't have to worry about what this module does; it is a helper base class | ||||||||||||||||||||
| 15 | for the different social classes. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 6 | has 'url' => ( isa => 'Str', is => 'rw', required => 1, default => '' ); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 6 | has 'useragent' => ( isa => 'LWP::UserAgent', is => 'ro', lazy_build => 1 ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 6 | ▶ | sub _build_useragent { | ||||||||||||||||||
|
Subroutine
_build_useragent: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 6 | my $self = shift; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 6 | return LWP::UserAgent->new; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 6 | ▶ | sub get_url_json { | ||||||||||||||||||
|
Subroutine
get_url_json: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||
| 30 | 6 | my $self = shift; | |||||||||||||||||||
| 31 | 6 | ▶ | my $url = shift || $self->url; | ||||||||||||||||||
|
Condition33%1/3
shift() || $self->url
MC/DC0%0/2
shift() || $self->url
shift()
$self->url
Truth table33%1/3
A || B
A= shift()B= $self->url
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 6 | ▶ | if ( $url =~ m,(file://.+), ) { # For testing against local files | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 6 | $url = $1; | |||||||||||||||||||
| 35 | 6 | $url =~ s/"$//; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 6 | my $response = $self->useragent->get( $url ); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 6 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 6 | return JSON::decode_json( $response->content ); | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||
| 44 | 0 | return undef; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # | ||||||||||||||||||||
| 49 | # The End | ||||||||||||||||||||
| 50 | # | ||||||||||||||||||||
| 51 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 6 | 1; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | Copyright 2013-2014 Tore Aursand. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 60 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||
| 61 | copy of the full license at: | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||
| 66 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||
| 67 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||
| 68 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||
| 71 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||
| 72 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||
| 75 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||
| 78 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||
| 79 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||
| 80 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||
| 81 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||
| 82 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||
| 83 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||
| 84 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||
| 87 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||
| 88 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||
| 89 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||
| 90 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||
| 91 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||
| 92 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||
| 93 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||