| 1 | package Net::Social::Mapper::Persona::Flickr; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use base qw(Net::Social::Mapper::Persona::Generic); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 4 | ▶ | use Feed::Find; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use JSON::Any; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 4 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | our $FLICKR_API_KEY = 'efe286838b28127e10271d239dec10bf'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Net::Social::Mapper::Person::Flickr - the persona for a Flickr account | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head2 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | See C<Net::Social::Mapper> | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | ▶ | sub _init { | ||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=38.4
| |||||||||||||||||||||
| 23 | 1 | my $self = shift; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # Guess at a bunch of stuff | ||||||||||||||||||||
| 26 | 1 | $self = $self->SUPER::_init; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | if ($self->{user} =~ m!^\d+@.+!) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | $self->{id} = delete $self->{user}; | |||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||
| 31 | 0 | ▶ | $self->{id} = $self->_fetch_nsid($self->{user}) || return $self; | ||||||||||||||||||
|
Condition0%0/2
$self->_fetch_nsid($self->{'user'}) || (return $self)
MC/DC0%0/1
$self->_fetch_nsid($self->{'user'}) || (return $self)
$self->_fetch_nsid($self->{'user'})
Truth table0%0/2
A
A= $self->_fetch_nsid($self->{'user'})
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | 0 | for my $format (qw(atom rss_200)) { | |||||||||||||||||||
| 34 | 0 | push @{$self->{feeds}}, "http://api.flickr.com/services/feeds/photos_public.gne?id=$self->{id}&lang=en-us&format=${format}"; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # Now try and get the actual values from flickr | ||||||||||||||||||||
| 38 | 0 | ▶ | my $info = $self->_fetch_userinfo($self->{id}) || return $self; | ||||||||||||||||||
|
Condition0%0/2
$self->_fetch_userinfo($self->{'id'}) || (return $self)
MC/DC0%0/1
$self->_fetch_userinfo($self->{'id'}) || (return $self)
$self->_fetch_userinfo($self->{'id'})
Truth table0%0/2
A
A= $self->_fetch_userinfo($self->{'id'})
| |||||||||||||||||||||
| 39 | 0 | $self->{full_name} = $info->{realname}->{_content}; | |||||||||||||||||||
| 40 | 0 | $self->{profile} = $info->{profileurl}->{_content}; | |||||||||||||||||||
| 41 | 0 | $self->{homepage} = $info->{photosurl}->{_content}; | |||||||||||||||||||
| 42 | 0 | ▶ | ($self->{user}) = ($self->{homepage} =~ m!/([^/]+)/?$!) unless defined $self->{user}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | # See http://www.flickr.com/services/api/misc.buddyicons.html | ||||||||||||||||||||
| 44 | 0 | ▶ | if ($info->{iconserver}>0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | my $farm = $info->{iconfarm}; | |||||||||||||||||||
| 46 | 0 | my $serv = $info->{iconserver}; | |||||||||||||||||||
| 47 | 0 | my $id = $self->{id}; | |||||||||||||||||||
| 48 | 0 | $self->{photo} = "http://farm${farm}.static.flickr.com/${serv}/buddyicons/${id}.jpg" | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | sub _fetch_nsid { | ||||||||||||||||||
|
Subroutine
_fetch_nsid: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||
| 57 | 0 | my $user = shift; | |||||||||||||||||||
| 58 | 0 | ▶ | my $info = $self->_do_flickr('flickr.urls.lookupUser', url => "http://flickr.com/photos/${user}/") || return; | ||||||||||||||||||
|
Condition0%0/2
$self->_do_flickr('flickr.urls.lookupUser', 'url', "http://flickr.com/photos/$user/") || (return)
MC/DC0%0/1
$self->_do_flickr('flickr.urls.lookupUser', 'url', "http://flickr.com/photos/$user/") || (return)
$self->_do_flickr('flickr.urls.lookupUser', 'url', "http://flickr.com/photos/$user/")
Truth table0%0/2
A
A= $self->_do_flickr('flickr.urls.lookupUser', 'url', "http://flickr.com/photos/$user/")
| |||||||||||||||||||||
| 59 | 0 | return $info->{user}->{id}; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | sub _fetch_userinfo { | ||||||||||||||||||
|
Subroutine
_fetch_userinfo: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||
| 64 | 0 | my $id = shift; | |||||||||||||||||||
| 65 | 0 | ▶ | my $key = $self->{_flickr_api_key} || $FLICKR_API_KEY; | ||||||||||||||||||
|
Condition0%0/3
$self->{'_flickr_api_key'} || $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
MC/DC0%0/2
$self->{'_flickr_api_key'} || $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
$self->{'_flickr_api_key'}
$Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
Truth table0%0/3
A || B
A= $self->{'_flickr_api_key'}B= $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
| |||||||||||||||||||||
| 66 | 0 | my $info = $self->_do_flickr('flickr.people.getInfo', user_id => $id ); | |||||||||||||||||||
| 67 | 0 | return $info->{person}; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | sub _do_flickr { | ||||||||||||||||||
|
Subroutine
_do_flickr: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||
| 72 | 0 | my $method = shift; | |||||||||||||||||||
| 73 | 0 | my %params = @_; | |||||||||||||||||||
| 74 | 0 | $params{method} = $method; | |||||||||||||||||||
| 75 | 0 | ▶ | $params{api_key} = $self->{_flickr_api_key} || $FLICKR_API_KEY; | ||||||||||||||||||
|
Condition0%0/3
$self->{'_flickr_api_key'} || $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
MC/DC0%0/2
$self->{'_flickr_api_key'} || $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
$self->{'_flickr_api_key'}
$Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
Truth table0%0/3
A || B
A= $self->{'_flickr_api_key'}B= $Net::Social::Mapper::Persona::Flickr::FLICKR_API_KEY
| |||||||||||||||||||||
| 76 | 0 | $params{format} = 'json'; | |||||||||||||||||||
| 77 | 0 | $params{nojsoncallback} = 1; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | my $url = URI->new("http://www.flickr.com/services/rest/"); | |||||||||||||||||||
| 80 | 0 | $url->query_form(%params); | |||||||||||||||||||
| 81 | 0 | ▶ | my $page = $self->mapper->get("$url") || return; | ||||||||||||||||||
|
Condition0%0/2
$self->mapper->get("$url") || (return)
MC/DC0%0/1
$self->mapper->get("$url") || (return)
$self->mapper->get("$url")
Truth table0%0/2
A
A= $self->mapper->get("$url")
| |||||||||||||||||||||
| 82 | 0 | return eval { $self->_json->decode($page) }; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 4 | 1; | |||||||||||||||||||
| 86 | |||||||||||||||||||||