blib/lib/Net/SocialGraph.pm

filter: Statementstmt 50.0% 15 / 30 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 48.8% 22 / 45 CC 3 SCAR 12.0
CC
3
Cov
44%
get
6.0
get_json
6.0
new
2.0
CRAP 3.3
↑ Summary
1 package Net::SocialGraph;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use JSON::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use LWP::Simple qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.1';
9  
10 2 my $url = 'http://socialgraph.apis.google.com/lookup';
11  
12 =head1 NAME
13  
14 Net::SocialGraph - interact with Google's Social Graph API
15  
16 =head1 SYNOPIS
17  
18 my $sg = Net::SocialGraph->new(%options); # see below
19 my $res = $sg->get(@urls);
20  
21 =head1 DESCRIPTION
22  
23 This is a paper thin wrapper round Google's Social Graph API.
24  
25 http://code.google.com/apis/socialgraph/
26  
27 You should read the docs there for more information about options
28 and the format of the response.
29  
30 =head1 METHODS
31  
32 =cut
33  
34 =head2 new [opt[s]]
35  
36 Create a new Social Graph object.
37  
38 Can optionally take, err, some options.
39  
40 =over 4
41  
42 =item edo (boolean)
43  
44 Return edges out from returned nodes.
45  
46 =item edi (boolean)
47  
48 Return edges in to returned nodes.
49  
50 =item fme (boolean)
51  
52 Follow me links, also returning reachable nodes.
53  
54 =item pretty (boolean)
55  
56 Pretty-print returned JSON.
57  
58 =item callback (string matching /^[\w\.]+$/)
59  
60 JSONP callback function.
61  
62 You shouldn't ever have to use this but I put it in for completeness.
63
64 =item sgn (boolean)
65  
66 Return internal representation of nodes.
67  
68 =back
69  
70 =cut
71  
72 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
73 0 my $class = shift;
74 0 my %opts = @_;
75 0 return bless \%opts, $class;
76 }
77  
78 =head2 get <uri[s]>
79  
80 Fetch the information about the nodes specified in the uris.
81  
82 Returns a nested data structure representing the results. This
83 will be in the form of a hashref.
84  
85 The key C<canonical_mapping> contains another hashref which maps
86 each uri given to its canonical form.
87  
88 The key C<nodes> contains a hashref with keys for each uri given.
89 The contents of those hashrefs (do keep up) depend on the options
90 given.
91  
92 You can read more information about node uris here
93  
94 http://code.google.com/apis/socialgraph/docs/api.html#query
95  
96  
97 =cut
98  
99 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
100 0 my $self = shift;
101 0 my @urls = @_;
102 0 ▶ my $json = $self->get_json(@urls) || return undef;
Condition0%0/2
$self->get_json(@urls) || (return undef)
l!l
00
MC/DC0%0/1
$self->get_json(@urls) || (return undef)
$self->get_json(@urls)
Truth table0%0/2
A
A= $self->get_json(@urls)
Aresult
11
00
103 0 return JSON::Any->jsonToObj($json);
104  
105 }
106  
107 =head2 get_json <uri[s]>
108  
109 The same as above but returns raw JSON.
110  
111 =cut
112  
113 0 ▶sub get_json {
Subroutine get_json: not called CC=2 SCAR=17.9
Pod documented
114 0 my $self = shift;
115 0 my @urls = @_;
116 0 ▶ return undef unless @urls;
Branch: 1 branch
BranchTrueFalseTotal
unless @urls 0 0 0
117 0 my %opts = %$self;
118 0 $opts{q} = join(",", @urls);
119  
120 0 my $uri = URI->new($url);
121 0 $uri->query_form(%opts);
122  
123 0 return LWP::Simple::get("$uri");
124  
125 }
126  
127 =head1 AUTHOR
128  
129 Simon Wistow <simon@thegestalt.org>
130  
131 =head1 COPYRIGHT
132  
133 Copyright 2008, Simon Wistow
134  
135 Distributed under the same terms as Perl itself.
136  
137 =cut
138  
139 2 1;
↑ Summary