Social/Facebook.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 90.9% 40 / 44 CC 3 SCAR 5.5
CC
3
Cov
89%
_build_data
3.4
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« Social/StumbleUpon.pm ↑ Summary Social/LinkedIn.pm »
1 package URL::Social::Facebook;
2 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 extends 'URL::Social::BASE';
6  
7 =head1 NAME
8  
9 URL::Social::Facebook - Interface to the Facebook API.
10  
11 =head1 DESCRIPTION
12  
13 Do not use this module directly. Access it from L<URL::Social> instead;
14  
15 use URL::Social;
16  
17 my $social = URL::Social->new(
18 url => '...',
19 );
20  
21 print $social->facebook->share_count . "\n";
22 print $social->facebook->like_count . "\n";
23  
24 # ...
25  
26 =head1 METHODS
27  
28 =cut
29  
30 6 has 'data' => ( isa => 'Maybe[HashRef]', is => 'ro', lazy_build => 1 );
31 6 has 'share_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 );
32 6 has 'like_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 );
33 6 has 'comment_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 );
34 6 has 'click_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 );
35 6 has 'total_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 );
36  
37 1 ▶sub _build_data {
Subroutine _build_data: called CC=3 SCAR=12.3
38 1 my $self = shift;
39  
40 1 my $url = 'https://graph.facebook.com/fql?q=SELECT like_count, total_count, share_count, click_count, comment_count FROM link_stat WHERE url = "' . $self->url . '"';
41  
42 1 ▶ if ( my $json = $self->get_url_json($url) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $json = $self->get_url_json($url)) { } 1 0 1
43 1 ▶ if ( my $data = $json->{data}->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $json->{'data'}[0]) { } 1 0 1
44 1 return $data;
45 }
46 else {
47 0 return undef;
48 }
49 }
50 else {
51 0 return undef;
52 }
53 }
54  
55 =head2 share_count
56  
57 Returns the number of times the URL in question has been shared among Facebook
58 users.
59  
60 Returns undef if it fails to retrieve the data from Facebook.
61  
62 =cut
63  
64 1 ▶sub _build_share_count {
Subroutine _build_share_count: called CC=1 SCAR=0.0
65 1 my $self = shift;
66  
67 1 return $self->data->{share_count};
68 }
69  
70 =head2 like_count
71  
72 Returns the number of times the URL in question has been liked among Facebook
73 users.
74  
75 Returns undef if it fails to retrieve the data from Facebook.
76  
77 =cut
78  
79 1 ▶sub _build_like_count {
Subroutine _build_like_count: called CC=1 SCAR=0.0
80 1 my $self = shift;
81  
82 1 return $self->data->{like_count};
83 }
84  
85 =head2 comment_count
86  
87 Returns the number of times the URL in question has been commented on among
88 Facebook users.
89  
90 Returns undef if it fails to retrieve the data from Facebook.
91  
92 =cut
93  
94 1 ▶sub _build_comment_count {
Subroutine _build_comment_count: called CC=1 SCAR=0.0
95 1 my $self = shift;
96  
97 1 return $self->data->{comment_count};
98 }
99  
100 =head2 click_count
101  
102 Returns the number of times the URL in question has been click on among Facebook
103 users.
104  
105 Returns undef if it fails to retrieve the data from Facebook.
106  
107 =cut
108  
109 1 ▶sub _build_click_count {
Subroutine _build_click_count: called CC=1 SCAR=0.0
110 1 my $self = shift;
111  
112 1 return $self->data->{click_count};
113 }
114  
115 =head2 total_count
116  
117 Returns the total number of shares, likes, comments and clicks for the URL in
118 question.
119  
120 Returns undef if it fails to retrieve the data from Facebook.
121  
122 =cut
123  
124 1 ▶sub _build_total_count {
Subroutine _build_total_count: called CC=1 SCAR=0.0
125 1 my $self = shift;
126  
127 1 return $self->data->{total_count};
128 }
129  
130 #
131 # The End
132 #
133 6 __PACKAGE__->meta->make_immutable;
134  
135 6 1;
136  
137 =head1 LICENSE AND COPYRIGHT
138  
139 Copyright 2013-2014 Tore Aursand.
140  
141 This program is free software; you can redistribute it and/or modify it
142 under the terms of the the Artistic License (2.0). You may obtain a
143 copy of the full license at:
144  
145 L<http://www.perlfoundation.org/artistic_license_2_0>
146  
147 Any use, modification, and distribution of the Standard or Modified
148 Versions is governed by this Artistic License. By using, modifying or
149 distributing the Package, you accept this license. Do not use, modify,
150 or distribute the Package, if you do not accept this license.
151  
152 If your Modified Version has been derived from a Modified Version made
153 by someone other than you, you are nevertheless required to ensure that
154 your Modified Version complies with the requirements of this license.
155  
156 This license does not grant you the right to use any trademark, service
157 mark, tradename, or logo of the Copyright Holder.
158  
159 This license includes the non-exclusive, worldwide, free-of-charge
160 patent license to make, have made, use, offer to sell, sell, import and
161 otherwise transfer the Package with respect to any patent claims
162 licensable by the Copyright Holder that are necessarily infringed by the
163 Package. If you institute patent litigation (including a cross-claim or
164 counterclaim) against any party alleging that the Package constitutes
165 direct or contributory patent infringement, then this Artistic License
166 to you shall terminate on the date that such litigation is filed.
167  
168 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
169 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
170 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
171 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
172 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
173 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
174 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
175 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
« Social/StumbleUpon.pm ↑ Summary Social/LinkedIn.pm »