Graph/Publish/Post.pm

filter: Statementstmt 23.9% 28 / 117 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 9.6% 3 / 31 Podpod 100% 15 / 15 totaltotal 23.3% 46 / 197 CC 19 SCAR 37.1
CC
19
Cov
19%
__ANON__
156.0
__ANON__
6.0
__ANON__
6.0
CRAP 40.8
« Graph/Query.pm ↑ Summary Graph/Page/Feed.pm »
1 package Facebook::Graph::Publish::Post;
2 4 $Facebook::Graph::Publish::Post::VERSION = '1.1205';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends 'Facebook::Graph::Publish';
6  
7 4 ▶use constant object_path => '/feed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 has message => (
10 is => 'rw',
11 predicate => 'has_message',
12 );
13  
14 0 ▶sub set_message {
Subroutine set_message: not called CC=1 SCAR=6.9
Pod documented
15 0 my ($self, $message) = @_;
16 0 $self->message($message);
17 0 return $self;
18 }
19  
20 4 has picture_uri => (
21 is => 'rw',
22 predicate => 'has_picture_uri',
23 );
24  
25 0 ▶sub set_picture_uri {
Subroutine set_picture_uri: not called CC=1 SCAR=6.9
Pod documented
26 0 my ($self, $picture) = @_;
27 0 $self->picture_uri($picture);
28 0 return $self;
29 }
30  
31  
32 4 has link_uri => (
33 is => 'rw',
34 predicate => 'has_link_uri',
35 );
36  
37 0 ▶sub set_link_uri {
Subroutine set_link_uri: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($self, $source) = @_;
39 0 $self->link_uri($source);
40 0 return $self;
41 }
42  
43  
44 4 has link_name => (
45 is => 'rw',
46 predicate => 'has_link_name',
47 );
48  
49 0 ▶sub set_link_name {
Subroutine set_link_name: not called CC=1 SCAR=6.9
Pod documented
50 0 my ($self, $source) = @_;
51 0 $self->link_name($source);
52 0 return $self;
53 }
54  
55  
56 4 has link_caption => (
57 is => 'rw',
58 predicate => 'has_link_caption',
59 );
60  
61 0 ▶sub set_link_caption {
Subroutine set_link_caption: not called CC=1 SCAR=6.9
Pod documented
62 0 my ($self, $source) = @_;
63 0 $self->link_caption($source);
64 0 return $self;
65 }
66  
67  
68 4 has link_description => (
69 is => 'rw',
70 predicate => 'has_link_description',
71 );
72  
73 0 ▶sub set_link_description {
Subroutine set_link_description: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($self, $source) = @_;
75 0 $self->link_description($source);
76 0 return $self;
77 }
78  
79 has target_countries => (
80 is => 'rw',
81 0 ▶ default => sub {[]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 lazy => 1,
83 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
84 4 predicate => 'has_target_countries',
85 );
86  
87 0 ▶sub set_target_countries {
Subroutine set_target_countries: not called CC=1 SCAR=6.9
Pod documented
88 0 my ($self, $source) = @_;
89 0 $self->target_countries($source);
90 0 return $self;
91 }
92  
93 has target_cities => (
94 is => 'rw',
95 0 ▶ default => sub {[]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 lazy => 1,
97 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
98 4 predicate => 'has_target_cities',
99 );
100  
101 0 ▶sub set_target_cities {
Subroutine set_target_cities: not called CC=1 SCAR=6.9
Pod documented
102 0 my ($self, $source) = @_;
103 0 $self->target_cities($source);
104 0 return $self;
105 }
106  
107 has target_regions => (
108 is => 'rw',
109 0 ▶ default => sub {[]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 lazy => 1,
111 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
112 4 predicate => 'has_target_regions',
113 );
114  
115 0 ▶sub set_target_regions {
Subroutine set_target_regions: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($self, $source) = @_;
117 0 $self->target_regions($source);
118 0 return $self;
119 }
120  
121 has target_locales => (
122 is => 'rw',
123 0 ▶ default => sub {[]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 lazy => 1,
125 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
126 4 predicate => 'has_target_locales',
127 );
128  
129 0 ▶sub set_target_locales {
Subroutine set_target_locales: not called CC=1 SCAR=6.9
Pod documented
130 0 my ($self, $source) = @_;
131 0 $self->target_locales($source);
132 0 return $self;
133 }
134  
135 4 has source => (
136 is => 'rw',
137 predicate => 'has_source',
138 );
139  
140 0 ▶sub set_source {
Subroutine set_source: not called CC=1 SCAR=6.9
Pod documented
141 0 my ($self, $source) = @_;
142 0 $self->source($source);
143 0 return $self;
144 }
145  
146 has actions => (
147 is => 'rw',
148 0 ▶ default => sub {[]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 lazy => 1,
150 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 0 0
151 4 predicate => 'has_actions',
152 );
153  
154 0 ▶sub set_actions {
Subroutine set_actions: not called CC=1 SCAR=6.9
Pod documented
155 0 my ($self, $actions) = @_;
156 0 $self->actions($actions);
157 0 return $self;
158 }
159  
160 0 ▶sub add_action {
Subroutine add_action: not called CC=1 SCAR=6.9
Pod documented
161 0 my ($self, $name, $link) = @_;
162 0 my $actions = $self->actions;
163 0 push @$actions, { name => $name, link => $link };
164 0 $self->actions($actions);
165 0 return $self;
166 }
167  
168 4 has privacy => (
169 is => 'rw',
170 predicate => 'has_privacy',
171 );
172  
173 has privacy_options => (
174 is => 'rw',
175 0 ▶ isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'HASH' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 0 0
176 0 ▶ default => sub {{}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
177 4 );
178  
179 0 ▶sub set_privacy {
Subroutine set_privacy: not called CC=1 SCAR=6.9
Pod documented
180 0 my ($self, $privacy, $options) = @_;
181 0 $self->privacy($privacy);
182 0 $self->privacy_options($options);
183 0 return $self;
184 }
185  
186 4 has 'properties' => (
187 is => 'rw',
188 predicate => 'has_properties'
189 );
190  
191 0 ▶sub set_properties {
Subroutine set_properties: not called CC=2 SCAR=17.9
Pod documented
192 0 my $self = shift;
193 0 ▶ my $properties = @_ % 2 ? shift @_ : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 0 0
194 0 $self->properties($properties);
195 0 return $self;
196 }
197  
198 0 ▶around get_post_params => sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
199 0 my ($orig, $self) = @_;
200 0 my $post = $orig->($self);
201 0 ▶ if ($self->has_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_message) 0 0 0
202 0 push @$post, message => $self->message;
203 }
204 0 ▶ if ($self->has_link_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_uri) 0 0 0
205 0 push @$post, link => $self->link_uri;
206 }
207 0 ▶ if ($self->has_link_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_name) 0 0 0
208 0 push @$post, name => $self->link_name;
209 }
210 0 ▶ if ($self->has_link_caption) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_caption) 0 0 0
211 0 push @$post, caption => $self->link_caption;
212 }
213 0 ▶ if ($self->has_link_description) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_description) 0 0 0
214 0 push @$post, description => $self->link_description;
215 }
216 0 ▶ if ($self->has_picture_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_picture_uri) 0 0 0
217 0 push @$post, picture => $self->picture_uri;
218 }
219 0 ▶ if ($self->has_source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_source) 0 0 0
220 0 push @$post, source => $self->source;
221 }
222 0 ▶ if ($self->has_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_actions) 0 0 0
223 0 foreach my $action (@{$self->actions}) {
224 0 push @$post, actions => JSON->new->encode($action);
225 }
226 }
227 0 ▶ if ($self->has_privacy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_privacy) 0 0 0
228 0 my %privacy = %{$self->privacy_options};
229 0 $privacy{value} = $self->privacy;
230 0 push @$post, privacy => JSON->new->encode(\%privacy);
231 }
232 0 ▶ if ($self->has_properties) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_properties) 0 0 0
233 0 push @$post, properties => JSON->new->encode($self->properties);
234 }
235 0 return $post;
236 4 };
237  
238 4 1;
239  
240 =head1 NAME
241  
242 Facebook::Graph::Publish::Post - Publish to a user's wall.
243  
244 =head1 VERSION
245  
246 version 1.1205
247  
248 =head1 SYNOPSIS
249  
250 my $fb = Facebook::Graph->new;
251  
252 $fb->add_post
253 ->set_message('I like beer.')
254 ->publish;
255  
256 my $response = $fb->add_post
257 ->set_message('I like Perl.')
258 ->set_picture_uri('http://www.perl.org/i/camel_head.png')
259 ->set_link_uri('http://www.perl.org/')
260 ->set_link_name('Perl.org')
261 ->set_link_caption('Perl is a programming language.')
262 ->set_link_description('A link to the Perl web site.')
263 ->publish;
264  
265  
266 =head1 DESCRIPTION
267  
268 This module gives you quick and easy access to publish to a user's Facebook feed.
269  
270 B<ATTENTION:> You must have the C<publish_stream> privilege to use this module.
271  
272 B<TIP:> Facebook seems to use these terms interchangeably: Feed, Post, News, Wall. So if you want to publish to a user's wall, this is the mechanism you use to do that.
273  
274 =head1 METHODS
275  
276 =head2 to ( id )
277  
278 Specify a profile id to post to. Defaults to 'me', which is the currently logged in user.
279  
280  
281 =head2 set_message ( message )
282  
283 Sets the text to post to the wall.
284  
285 =head3 message
286  
287 A string of text.
288  
289  
290 =head2 set_picture_uri ( uri )
291  
292 Sets the URI of a picture to be displayed in the message.
293  
294 =head3 uri
295  
296 A URI to a picture.
297  
298  
299 =head2 set_link_uri ( uri )
300  
301 Sets the URI of a link that viewers can click on for more information about whatever you posted in C<set_message>.
302  
303 =head3 uri
304  
305 A URI to a site.
306  
307  
308 =head2 set_link_name ( name )
309  
310 If you want to give the link you set in C<set_link_uri> a human friendly name, use this method.
311  
312 =head2 name
313  
314 A text string to be used as the name of the link.
315  
316  
317 =head2 set_link_caption ( caption )
318  
319 Sets a short blurb to be displayed below the link/picture.
320  
321 =head3 caption
322  
323 A text string.
324  
325  
326 =head2 set_link_description ( description )
327  
328 Sets a longer description of the site you're linking to. Can also be a portion of the article you're linking to.
329  
330 =head3 description
331  
332 A text string.
333  
334  
335 =head2 set_source ( uri )
336  
337 Sets a source URI for a flash or video file.
338  
339 =head3 uri
340  
341 The URI you wish to set. For example if you wanted to include a YouTube video:
342  
343 $post->set_source('http://www.youtube.com/watch?v=efsJRdJ6dog');
344  
345  
346 =head2 set_actions ( actions )
347  
348 Sets a list of actions (or links) that should go in the post as things people can do with the post. This allows for integration of the post with third party sites.
349  
350 =head3 actions
351  
352 An array reference of hash references containing C<name> / C<link> pairs.
353  
354 $post->actions([
355 {
356 name => 'Click Me!',
357 link => 'http://www.somesite.com/click',
358 },
359 ...
360 ]);
361  
362 =head2 add_action ( name, link )
363  
364 Adds an action to the list of actions set either by previously calling C<add_action> or by calling C<set_actions>.
365  
366 =head3 name
367  
368 The name of the action (the clickable label).
369  
370 =head3 link
371  
372 The URI of the action.
373  
374  
375  
376 =head2 set_privacy ( setting, options )
377  
378 A completely optional privacy setting.
379  
380 =head2 set_properties ( properties )
381  
382 "property" values assigned when the post is published. This is typically rendered as a list of links.
383  
384 $post->set_properties( { "search engine:" => { "text" => "Google", "href" => "http://www.google.com/" } } );
385  
386 =head3 setting
387  
388 The privacy setting. Choose from: EVERYONE, CUSTOM, ALL_FRIENDS, NETWORKS_FRIENDS, and FRIENDS_OF_FRIENDS. See L<http://developers.facebook.com/docs/reference/api/post> for changes in this list.
389  
390 =head3 options
391  
392 A hash reference of options to tweak the privacy setting. Some options are required depending on what privacy setting you chose. See L<http://developers.facebook.com/docs/reference/api/post> for details.
393  
394 $post->set_privacy('CUSTOM', { friends => 'SOME_FRIENDS', allow => [qw( 119393 993322 )] });
395  
396 =over
397  
398 =item friends
399  
400 A string that must be one of EVERYONE, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS.
401  
402 =item networks
403  
404 An array reference of network ids.
405  
406 =item allow
407  
408 An array reference of user ids.
409  
410 =item deny.
411  
412 An array reference of user ids.
413  
414 =back
415  
416  
417 =head2 set_target_countries ( countries )
418  
419 Makes a post only available to viewers in certain countries.
420  
421 $post->set_target_countries( ['US'] );
422  
423 =head3 countries
424  
425 An array reference of two letter country codes (upper case). You can find a list of country codes in the list of city ids here: L<http://developers.facebook.com/attachment/all_cities_final.csv>.
426  
427  
428 =head2 set_target_regions ( regions )
429  
430 Makes a post only available to viewers in certain regions.
431  
432 $post->set_target_regions( [6,53] );
433  
434 =head3 regions
435  
436 An array reference of region numbers however Facebook defines that. I've got no idea because their documentation sucks. I'm not even sure what a region is. Is it a region of a country? Of a continent? No idea. I do know it is an integer, but that's about it.
437  
438  
439  
440 =head2 set_target_cities ( cities )
441  
442 Makes a post only available to viewers in certain cities.
443  
444 $post->set_target_cities( [2547804] );
445  
446 =head3 cities
447  
448 An array reference of cities ids. In the example above I've listed Madison, WI. You can find a list of their cities here: L<http://developers.facebook.com/attachment/all_cities_final.csv>
449  
450  
451  
452 =head2 set_target_locales ( locales )
453  
454 Makes a post only available to viewers in certain locales.
455  
456 $post->set_target_locales( [6] );
457  
458 =head3 locales
459  
460 An array reference of locales ids. You can find their list of locales here: L<http://developers.facebook.com/attachment/locales_final.csv>
461  
462  
463  
464 =head2 publish ( )
465  
466 Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
467  
468 {"id":"1647395831_130068550371568"}
469  
470 =head1 LEGAL
471  
472 Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
473  
474 =cut
« Graph/Query.pm ↑ Summary Graph/Page/Feed.pm »