Graph/Page/Feed.pm

filter: Statementstmt 32.7% 19 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 25.0% 3 / 12 Podpod 71.4% 5 / 7 totaltotal 25.2% 27 / 107 CC 12 SCAR 36.4
CC
12
Cov
23%
__ANON__
90.0
published
12.0
object_path
6.0
CRAP 38.0
« Graph/Publish/Post.pm ↑ Summary Graph/Publish/Photo.pm »
1 package Facebook::Graph::Page::Feed;
2 4 $Facebook::Graph::Page::Feed::VERSION = '1.1205';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends 'Facebook::Graph::Publish';
6  
7 4 has page_id => (
8 is => 'rw',
9 predicate => 'has_page_id',
10 );
11  
12 0 ▶sub set_page_id {
Subroutine set_page_id: not called CC=1 SCAR=6.9
Pod documented
13 0 my ($self, $page_id) = @_;
14 0 $self->object_name(''); # not sure it's a good way here
15 0 $self->set_published(1); # it's a default value on FB side;
16 0 $self->page_id($page_id);
17 0 return $self;
18 }
19  
20 4 ▶use subs qw(object_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶sub object_path{
Subroutine object_path: not called CC=2 SCAR=17.9
22 0 my $s = shift;
23  
24 0 ▶ return $s->has_page_id ?
Branch: 1 branch
BranchTrueFalseTotal
$s->has_page_id ? : 0 0 0
25 sprintf( '%s/feed', $s->page_id )
26 : die "You must set_page_id first";
27 }
28  
29 4 has message => (
30 is => 'rw',
31 predicate => 'has_message',
32 );
33  
34 0 ▶sub set_message {
Subroutine set_message: not called CC=1 SCAR=6.9
Pod documented
35 0 my ($self, $message) = @_;
36 0 $self->message($message);
37 0 return $self;
38 }
39  
40 4 has link_uri => (
41 is => 'rw',
42 predicate => 'has_link_uri',
43 );
44  
45 0 ▶sub set_link_uri {
Subroutine set_link_uri: not called CC=1 SCAR=6.9
Pod documented
46 0 my ($self, $link_uri) = @_;
47 0 $self->link_uri($link_uri);
48 0 return $self;
49 }
50  
51 4 has backdated_time => (
52 is => 'rw',
53 predicate => 'has_backdated_time',
54 );
55  
56 sub set_backdated_time
57 0 ▶{
Subroutine set_backdated_time: not called CC=1 SCAR=6.9
Pod documented
58 0 my ($self, $backdated_time) = @_;
59 0 $self->backdated_time($backdated_time);
60 0 return $self;
61 }
62  
63 4 has scheduled_publish_time => (
64 is => 'rw',
65 predicate => 'has_scheduled_publish_time'
66 );
67  
68 sub set_scheduled_publish_time
69 0 ▶{
Subroutine set_scheduled_publish_time: not called CC=1 SCAR=6.9
Pod documented
70 0 my ($self, $scheduled_publish_time) = @_;
71 0 $self->scheduled_publish_time($scheduled_publish_time);
72 0 return $self;
73 }
74  
75 4 has published => (
76 is => 'rw',
77 predicate => 'has_published',
78 reader => '_get_published',
79 writer => '_set_published',
80 );
81  
82 sub published
83 0 ▶{
Subroutine published: not called CC=3 SCAR=24.8
Pod undocumented
84 0 my($self, $published) = @_;
85  
86 0 ▶ if( scalar @_ > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) 0 0 0
87 {
88 0 $self->_set_published($published);
89 }
90  
91 0 ▶ return $self->_get_published && $self->_get_published ne 'false';
Condition0%0/3
$self->_get_published && $self->_get_published ne 'false'
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_get_published && $self->_get_published ne 'false'
$self->_get_published $self->_get_published ne 'false'
Truth table0%0/3
A && B
A= $self->_get_publishedB= $self->_get_published ne 'false'
ABresult
0X0
100
111
92 }
93  
94 sub set_published
95 0 ▶{
Subroutine set_published: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my ($self, $published) = @_;
97 0 $self->published($published);
98 0 return $self;
99 }
100  
101 0 ▶around get_post_params => sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
102 0 my ($orig, $self) = @_;
103 0 my $post = $orig->($self);
104 0 ▶ if ($self->has_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_message) 0 0 0
105 0 push @$post, message => $self->message;
106 }
107 0 ▶ if ($self->has_link_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_uri) 0 0 0
108 0 push @$post, link => $self->link_uri;
109 }
110 0 ▶ if ($self->has_backdated_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_backdated_time) 0 0 0
111 0 push @$post, backdated_time => $self->backdated_time + 10*3600; # temporary fix for FB::Graph API
112 }
113 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_scheduled_publish_time and not $self->has_published && $self->published) 0 0 0
Condition0%0/6
$self->has_scheduled_publish_time and not $self->has_published && $self->published
!ll&&!rl&&r
000
$self->has_published && $self->published
!ll&&!rl&&r
000
MC/DC0%0/3
$self->has_scheduled_publish_time and not $self->has_published && $self->published
$self->has_scheduled_publish_time $self->has_published $self->published
Truth table0%0/4
A and not(B && C)
A= $self->has_scheduled_publish_timeB= $self->has_publishedC= $self->published
ABCresult
0XX0
1110
10X1
1101
114 $self->has_scheduled_publish_time
115 and (
116 not $self->has_published or not $self->published
117 )
118 ) {
119 0 push @$post, scheduled_publish_time => $self->scheduled_publish_time;
120 }
121 0 ▶ if ($self->has_published) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_published) 0 0 0
122 0 ▶ push @$post, published => $self->published ? 'true': 'false';
Branch: 1 branch
BranchTrueFalseTotal
$self->published ? : 0 0 0
123 }
124 0 return $post;
125 4 };
126  
127 4 1;
128  
129 =head1 NAME
130  
131 Facebook::Graph::Page::Feed - Add a post to a Facebook page.
132  
133 =head1 VERSION
134  
135 version 1.1205
136  
137 =head1 SYNOPSIS
138  
139 my $fb = Facebook::Graph->new;
140  
141 $fb->add_page_feed
142 ->set_page_id($page_id)
143 ->set_message('This is a test post')
144 ->set_backdated_time(time-3600)
145 ->set_scheduled_publish_time(time+3600)
146 ->set_published('false')
147 ->set_link_uri('http://mysite.com/testpage')
148 ->publish;
149  
150  
151 =head1 DESCRIPTION
152  
153 This module gives you quick and easy access to publish posts on FB pages.
154  
155 Implements publishing protocol available here:
156 L<https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/>
157  
158 B<ATTENTION:> You must have the page access token to use this module.
159 It's available in C<$fb->fetch('me/accounts')>, but, you must have a user
160 token with C<manage_page> permission.
161  
162 More information about tokens could be found here:
163 L<https://developers.facebook.com/docs/facebook-login/access-tokens>
164  
165 =head1 METHODS
166  
167 =head2 set_page_id ( page_id )
168  
169 Specify a page id to post to. This is required field and must be set before
170 publishing.
171  
172 =head2 set_message ( message )
173  
174 Sets the description of the link.
175  
176 =head3 message
177  
178 A string of text.
179  
180  
181 =head2 set_link_uri ( uri )
182  
183 Sets the URI to link to.
184  
185 =head3 uri
186  
187 A URI.
188  
189 =head2 set_backdated_time ( time )
190  
191 Set a date of your post, different from now. Just a backdate. Time should be a
192 timestamp, no fancy formats.
193  
194 =head2 set_scheduled_publish_time( time )
195  
196 Set a publishing time for scheduled posts. Time should be a desired timestamp of
197 post in future. Doesn't work with minutes from now, but works fine with hour+
198  
199 =head2 publish ( )
200  
201 Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
202  
203 {"id":"1647395831_130068550371568"}
204  
205  
206 =head1 LEGAL
207  
208 Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
209  
210 Facebook::Graph::Page::Feed is Copyright 2014 Alexandr Evstigneev (L<http://evstigneev.com>) and is licensed under the same terms as Perl itself.
211  
212 =cut
« Graph/Publish/Post.pm ↑ Summary Graph/Publish/Photo.pm »