blib/lib/ShipIt/Step/Facebook.pm

filter: Statementstmt 39.2% 20 / 51 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 27.1% 28 / 103 CC 16 SCAR 41.0
CC
16
Cov
24%
init
90.0
run
72.0
BEGIN
1.0
CRAP 60.5
↑ Summary
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'
l!l
00
MC/DC0%0/1
$conf->value('facebook.config') || '~/.shipit.facebook'
$conf->value('facebook.config')
Truth table0%0/2
A
A= $conf->value('facebook.config')
Aresult
11
00
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
BranchTrueFalseTotal
-e $config_file or die "facebook.config: $config_file does not exist\n" 0 0 0
19 0 ▶ -r $config_file || die "facebook.config: $config_file is not readable\n";
Branch: 1 branch
BranchTrueFalseTotal
-r $config_file or die "facebook.config: $config_file is not readable\n" 0 0 0
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
BranchTrueFalseTotal
defined $self->{"config"}{"access_token"} or die "${config_file}: no access_token defined\n" 0 0 0
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'
l!l
00
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')
Aresult
11
00
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'
l!l
00
$conf->value("facebook.target") or $self->{"config"}{"target"}
l!l&&r!l&&!r
000
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"}
ABresult
1X1
011
000
31  
32 0 $self->{distname} = $conf->value('facebook.distname');
33 0 ▶ defined $self->{distname} || print
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"distname"} or print "facebook.distname not defined; will try to read it from META.yml later.\n" 0 0 0
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
BranchTrueFalseTotal
if (not defined $self->{"distname"} and -e $metafile) 0 0 0
Condition0%0/3
not defined $self->{"distname"} and -e $metafile
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $meta->{"version"}
$version $meta->{"version"}
Truth table0%0/3
A ||= B
A= $versionB= $meta->{"version"}
ABresult
1X1
011
000
47 }
48 0 ▶ defined $self->{distname} || die
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"distname"} or die "facebook.distname not defined in config, and can't read it from META.yml\n" 0 0 0
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
l!l
00
MC/DC0%0/1
$vars{$1} || '%' . $1
$vars{$1}
Truth table0%0/2
A
A= $vars{$1}
Aresult
11
00
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
BranchTrueFalseTotal
if ($state->dry_run) 0 0 0
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
BranchTrueFalseTotal
if $res->is_error 0 0 0
80 }
81  
82 1 1;
83 __END__
↑ Summary