| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::SocialGraph; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 670 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 4 | 1 |  |  | 1 |  | 957 | use JSON::Any; | 
|  | 1 |  |  |  |  | 22339 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 5 | 1 |  |  | 1 |  | 5976 | use LWP::Simple qw(); | 
|  | 1 |  |  |  |  | 70813 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 6 | 1 |  |  | 1 |  | 8 | use URI; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 266 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '1.1'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | sub new { | 
| 73 | 0 |  |  | 0 | 1 |  | my $class = shift; | 
| 74 | 0 |  |  |  |  |  | my %opts  = @_; | 
| 75 | 0 |  |  |  |  |  | return bless \%opts, $class; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head2 get | 
| 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 contains another hashref which maps | 
| 86 |  |  |  |  |  |  | each uri given to its canonical form. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | The key C 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 |  |  |  |  |  |  | sub get { | 
| 100 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 101 | 0 |  |  |  |  |  | my @urls = @_; | 
| 102 | 0 |  | 0 |  |  |  | my $json = $self->get_json(@urls) || return undef; | 
| 103 | 0 |  |  |  |  |  | return JSON::Any->jsonToObj($json); | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head2 get_json | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | The same as above but returns raw JSON. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =cut | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | sub get_json { | 
| 114 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 115 | 0 |  |  |  |  |  | my @urls = @_; | 
| 116 | 0 | 0 |  |  |  |  | return undef unless @urls; | 
| 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 | 
| 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 |  |  |  |  |  |  | 1; |