Social.pm

filter: Statementstmt 64.2% 27 / 42 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 50.0% 1 / 2 totaltotal 63.1% 36 / 57 CC 3 SCAR 13.1
CC
3
Cov
61%
_services
12.0
services
2.0
service
2.0
CRAP 3.7
↑ Summary Social/Service.pm »
1 package Net::Social;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Module::Pluggable search_path => 'Net::Social::Service',
Subroutine BEGIN: called CC=1 SCAR=0.0
7 sub_name => '_fetch_services',
8 1 instantiate => 'new';
9  
10  
11  
12 # relationship constants
13 1 ▶use constant NONE => 0x0;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant FRIENDED => 0x1;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant FRIENDED_BY => 0x2;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant MUTUAL => 0x3; # not strictly needed but convenient
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 @EXPORT_OK = qw(NONE FRIENDED FRIENDED_BY MUTUAL);
19 1 %EXPORT_TAGS = ( all => [@EXPORT_OK] );
20 1 $VERSION = 0.4;
21  
22  
23 =head1 NAME
24  
25 Net::Social - abstracted interface for social networks
26  
27 =head1 SYNOPSIS
28  
29 use Net::Social qw(:all); # get constants
30  
31 # What services are available
32 my @services = Net::Social->services;
33  
34 # Fetch a handler for a service
35 my $service = Net::Social->service('LiveJournal');
36  
37 # what fields are needed to login
38 my %params = $service->params;
39  
40 foreach my $type (keys %params) {
41 print "To $type:\n"; # either read or write
42 foreach my $p (keys %$types{$type}) {
43 print $params{$type}->{$p}->{name}." : ".$params{$type}->{$p}->{description}."\n";
44 # also 'required' and 'sensitive'
45 }
46 }
47  
48 # login - my_params must have the required fields from %params
49 $service->login(%my_params);
50  
51 # now fetch your friends
52 my @friends = $service->friends;
53  
54 # add a friend
55 $service->add_friend($friend);
56
57 # remove a friend
58 $service->remove_friend($friend);
59
60  
61 =head1 CONSTANTS
62  
63 Optionally exports the constants
64  
65 NONE
66 FRIENDED
67 FRIENDED_BY
68 MUTUAL
69  
70 Which describe the type of relationship with a friend.
71  
72 It should be noted that
73  
74 MUTUAL = FRIENDED | FRIENDED_BY;
75  
76 but is provided for convenience.
77  
78 =head1 METHODS
79  
80 =cut
81  
82 0 ▶sub _services {
Subroutine _services: not called CC=3 SCAR=24.8
83 0 my $class = shift;
84 0 my %services;
85 0 for my $service ($class->_fetch_services) {
86 0 my $name = ref($service);
87 0 $name =~ s!^Net::Social::Service::!!;
88 0 ▶ next if $name =~ m!::!;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /::/ 0 0 0
89 0 $services{lc($name)} = $service;
90 }
91 0 return %services;
92 }
93 =head2 services
94  
95 A list of all services available.
96  
97 =cut
98  
99 0 ▶sub services {
Subroutine services: not called CC=1 SCAR=6.9
Pod undocumented
100 0 my $class = shift;
101 0 my %services = $class->_services();
102 0 return keys %services;
103 }
104  
105  
106 =head2 service <service name>
107  
108 Fetch the class for a given service
109  
110 Returns undef if that service isn't found.
111  
112 =cut
113  
114 0 ▶sub service {
Subroutine service: not called CC=1 SCAR=6.9
Pod documented
115 0 my $class = shift;
116 0 my $service = shift;
117 0 my %services = $class->_services();
118 0 return $services{lc($service)};
119  
120 }
121  
122 =head1 AUTHOR
123  
124 Simon Wistow <simon@thegestalt.org>
125  
126 =head1 COPYRIGHT
127  
128 Copyright, 2007 - Simon Wistow
129  
130 Distributed under the same terms as Perl itself
131  
132 =cut
↑ Summary Social/Service.pm »