line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ShipIt::Step::Facebook; |
2
|
1
|
|
|
1
|
|
23374
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1996
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
65552
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
4240
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2773
|
|
|
1
|
|
|
|
|
132
|
|
8
|
1
|
|
|
1
|
|
1049
|
use YAML 'LoadFile'; |
|
1
|
|
|
|
|
8664
|
|
|
1
|
|
|
|
|
77
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
11
|
use base qw(ShipIt::Step); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1112
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub init { |
13
|
0
|
|
|
0
|
1
|
|
my ($self, $conf) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
0
|
|
|
|
my $config_file = $conf->value('facebook.config') || '~/.shipit.facebook'; |
16
|
0
|
|
|
|
|
|
$config_file =~ s/~/$ENV{HOME}/; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
-e $config_file || die "facebook.config: $config_file does not exist\n"; |
19
|
0
|
0
|
|
|
|
|
-r $config_file || die "facebook.config: $config_file is not readable\n"; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$self->{config} = LoadFile($config_file); |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
defined $self->{config}{access_token} or |
24
|
|
|
|
|
|
|
die "$config_file: no access_token defined\n"; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
0
|
|
|
|
$self->{message} = |
27
|
|
|
|
|
|
|
$conf->value('facebook.message') || 'shipped %d %v - soon at %f'; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
0
|
|
|
|
$self->{target} = |
30
|
|
|
|
|
|
|
$conf->value('facebook.target') || $self->{config}{target} || 'me'; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->{distname} = $conf->value('facebook.distname'); |
33
|
0
|
0
|
|
|
|
|
defined $self->{distname} || print |
34
|
|
|
|
|
|
|
"facebook.distname not defined; will try to read it from META.yml later.\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub run { |
38
|
0
|
|
|
0
|
1
|
|
my ($self, $state) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $version = $state->version; |
41
|
0
|
|
|
|
|
|
my $metafile = 'META.yml'; |
42
|
0
|
0
|
0
|
|
|
|
if (!(defined $self->{distname}) && -e $metafile) { |
43
|
0
|
|
|
|
|
|
print "facebook.distname not defined; reading $metafile...\n"; |
44
|
0
|
|
|
|
|
|
my $meta = LoadFile($metafile); |
45
|
0
|
|
|
|
|
|
$self->{distname} = $meta->{name}; |
46
|
0
|
|
0
|
|
|
|
$version ||= $meta->{version}; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
defined $self->{distname} || die |
49
|
|
|
|
|
|
|
"facebook.distname not defined in config, and can't read it from META.yml\n"; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my %vars = ( |
52
|
|
|
|
|
|
|
d => $self->{distname}, |
53
|
|
|
|
|
|
|
u => "http://search.cpan.org/dist/$self->{distname}", |
54
|
|
|
|
|
|
|
f => "http://frepan.org/dist/$self->{distname}", |
55
|
|
|
|
|
|
|
v => $version, |
56
|
|
|
|
|
|
|
'%' => '%' |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
(my $message = $self->{message}) =~ s/%(.)/ $vars{$1} || '%'.$1 /ge; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# warn(), don't die(), if we couldn't send the message, because this |
62
|
|
|
|
|
|
|
# step will presumably come after uploading to CPAN, so we don't want |
63
|
|
|
|
|
|
|
# to skip the rest of the shipit process just because of that. |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ($state->dry_run) { |
66
|
0
|
|
|
|
|
|
warn "*** DRY RUN, not facebooking!\n"; |
67
|
0
|
|
|
|
|
|
warn "message: $message\n"; |
68
|
0
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
72
|
0
|
|
|
|
|
|
my $target = $self->{target}; |
73
|
0
|
|
|
|
|
|
my $res = $ua->request( |
74
|
|
|
|
|
|
|
POST "https://graph.facebook.com/$target/feed", [ |
75
|
|
|
|
|
|
|
access_token => $self->{config}{access_token}, |
76
|
|
|
|
|
|
|
message => $message, |
77
|
|
|
|
|
|
|
] |
78
|
|
|
|
|
|
|
); |
79
|
0
|
0
|
|
|
|
|
warn "couldn't send message to facebook\n" if $res->is_error; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |