Social/Service.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 37 CC 2 SCAR 11.0
CC
2
Cov
0%
login
6.0
new
2.0
params
2.0
CRAP 3.0
1 package Net::Social::Service;
2  
3 use strict;
4  
5 =head1 NAME
6  
7 Net::Social::Service - the base package for all the Net::Social plugins
8  
9 =head1 METHODS
10  
11 my $service = Net::Social->service('LiveJournal');
12  
13 or
14  
15 my $service = Net::Social::Service::LiveJournal->new;
16  
17  
18 Get the params needed
19  
20 my %params = Net::Social::Service::LiveJournal->params;
21  
22 or
23 my %params = $service->params;
24  
25 for my $what (qw(read write)) {
26 print "Can $what\n" if $params{$what};
27 }
28  
29 # list what keys are needed to login
30 foreach my $key (keys %$params{read}) {
31 print "$key: ".$params{read}->{$key}."\n";
32 }
33
34 then
35  
36 $service->login(%params);
37  
38 foreach my $friend ($service->friends) {
39 print "$friend->{name} $friend->{type}\n";
40 }
41  
42  
43 $service->add_friend("frank");
44 $service->remove_friend("frank");
45
46  
47 =cut
48  
49 =head2 new
50  
51 Create a new Service
52  
53 =cut
54  
55 sub new {
56 my $class = shift;
57 return bless { _logged_in => 0 }, $class;
58 }
59  
60 =head2 params
61  
62 What fields are needed to log in to this service.
63  
64 This will return a hash ref, the keys of which will
65 be either C<read> or C<write> or one of each. If you log in
66 using the C<write> params you will also be able to read.
67  
68 Each of those will, in turn, be a hash ref the keys of which described
69 what is needed. In turn I<their> values will be another hash ref which
70 can contain the fields
71  
72 =over 4
73  
74 =item description.
75  
76 Always present. A description of the field.
77  
78 =item required
79  
80 Defaults to 0. Dictates whether this field is required or optional.
81  
82 =item sensitive
83  
84 Defaults to 0. Whether or not this field is sensitive or not.
85  
86 By sensitive we mean that it compromises the user's account.
87 Examples of this might be, say, a password as opposed to a
88 authorisation token.
89  
90 This is a bit of a judgment call, to be honest.
91  
92 =cut
93  
94 sub params {
95 my $class = shift;
96 return ();
97 }
98  
99  
100 =head2 login <params>
101  
102 Login in to this site.
103  
104 =cut
105  
106 sub login {
107 my $self = shift;
108 my %params = @_;
109  
110 my %keys = $self->params;
111 foreach my $p (keys %keys) {
112 return undef if $keys{$p}->{required} && !exists $params{$p};
113 }
114 $self->{_logged_in} = 1;
115 $self->{_details} = \%params;
116 return 1;
117 }
118  
119  
120 =head2 friends
121  
122 All your friends on the site.
123  
124 The friends will be return as a list of hash refs.
125  
126 The hash refs will contain various fields depending
127 on the service returning the data such as C<name> (the
128 person's full name), C<uid> (the uid on the service),
129 C<username> (a username on the service, may be the same
130 as uid). However each one will definitely contain C<type>
131 which will be one of 4 values, defined as constants in
132 C<Net::Social>.
133  
134 =over4
135  
136 =item NONE
137  
138 There's no defined relationship between the two of you.
139  
140 =item FRIENDED
141  
142 You've friended them but they haven't friended you.
143  
144 =item FRIENDED_BY
145  
146 They've friended you but you haven't friended them.
147  
148 =item MUTUAL
149  
150 You've both friended each other. C<MUTUAL> is defined as
151  
152 MUTUAL = FRIENDED | FRIENDED_BY
153  
154 =back
155  
156 In the future I may make all services return a C<key> field or
157 similar which will be the field needed for adding or deleting.
158  
159 =cut
160  
161 sub friends {
162 my $self = shift;
163 return ();
164 }
165  
166 =head2 add_friend <username>
167  
168 Add a friend.
169  
170 =cut
171  
172 sub add_friend { }
173  
174  
175 =head2 remove_friend <username>
176  
177 Remove a friend.
178  
179 =cut
180  
181 sub remove_friend { }
182  
183 1;