| 1 | package ShipIt::Step::Facebook; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use YAML 'LoadFile'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use base qw(ShipIt::Step); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 0 | my ($self, $conf) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $config_file = $conf->value('facebook.config') || '~/.shipit.facebook'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf->value('facebook.config') || '~/.shipit.facebook'
MC/DC0%0/1
$conf->value('facebook.config') || '~/.shipit.facebook'
$conf->value('facebook.config')
Truth table0%0/2
A
A= $conf->value('facebook.config')
| |||||||||||||||||||||||||||||
| 16 | 0 | $config_file =~ s/~/$ENV{HOME}/; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | -e $config_file || die "facebook.config: $config_file does not exist\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | -r $config_file || die "facebook.config: $config_file is not readable\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | $self->{config} = LoadFile($config_file); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | defined $self->{config}{access_token} or | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | die "$config_file: no access_token defined\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $self->{message} = | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $conf->value('facebook.message') || 'shipped %d %v - soon at %f'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf->value('facebook.message') || 'shipped %d %v - soon at %f'
MC/DC0%0/1
$conf->value('facebook.message') || 'shipped %d %v - soon at %f'
$conf->value('facebook.message')
Truth table0%0/2
A
A= $conf->value('facebook.message')
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $self->{target} = | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $conf->value('facebook.target') || $self->{config}{target} || 'me'; | ||||||||||||||||||||||||||
|
Condition0%0/5
$conf->value('facebook.target') || $self->{'config'}{'target'} || 'me'
$conf->value("facebook.target") or $self->{"config"}{"target"}
MC/DC0%0/2
$conf->value('facebook.target') || $self->{'config'}{'target'} || 'me'
$conf->value("facebook.target")
$self->{"config"}{"target"}
Truth table0%0/3
A or B
A= $conf->value("facebook.target")B= $self->{"config"}{"target"}
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | $self->{distname} = $conf->value('facebook.distname'); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | defined $self->{distname} || print | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | "facebook.distname not defined; will try to read it from META.yml later.\n"; | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $state) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $version = $state->version; | |||||||||||||||||||||||||||
| 41 | 0 | my $metafile = 'META.yml'; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (!(defined $self->{distname}) && -e $metafile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"distname"} and -e $metafile
MC/DC0%0/2
not defined $self->{"distname"} and -e $metafile
not defined $self->{"distname"}
-e $metafile
Truth table0%0/3
not(A) and B
A= not defined $self->{"distname"}B= -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 | ▶ | $version ||= $meta->{version}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$version ||= $meta->{"version"}
MC/DC0%0/2
$version ||= $meta->{"version"}
$version
$meta->{"version"}
Truth table0%0/3
A ||= B
A= $versionB= $meta->{"version"}
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | defined $self->{distname} || die | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | "facebook.distname not defined in config, and can't read it from META.yml\n"; | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | my %vars = ( | ||||||||||||||||||||||||||||
| 52 | d => $self->{distname}, | ||||||||||||||||||||||||||||
| 53 | 0 | u => "http://search.cpan.org/dist/$self->{distname}", | |||||||||||||||||||||||||||
| 54 | f => "http://frepan.org/dist/$self->{distname}", | ||||||||||||||||||||||||||||
| 55 | v => $version, | ||||||||||||||||||||||||||||
| 56 | '%' => '%' | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | (my $message = $self->{message}) =~ s/%(.)/ $vars{$1} || '%'.$1 /ge; | ||||||||||||||||||||||||||
|
Condition0%0/2
$vars{$1} || '%' . $1
MC/DC0%0/1
$vars{$1} || '%' . $1
$vars{$1}
Truth table0%0/2
A
A= $vars{$1}
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ($state->dry_run) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | my $res = $ua->request( | ||||||||||||||||||||||||||||
| 74 | POST "https://graph.facebook.com/$target/feed", [ | ||||||||||||||||||||||||||||
| 75 | access_token => $self->{config}{access_token}, | ||||||||||||||||||||||||||||
| 76 | 0 | message => $message, | |||||||||||||||||||||||||||
| 77 | ] | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | warn "couldn't send message to facebook\n" if $res->is_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | 1; | |||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||