blib/lib/Benchmark/Report/GitHub.pm

filter: Statementstmt 15.3% 12 / 78 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.8% 3 / 7 Podpod 100% 4 / 4 totaltotal 14.7% 19 / 129 SCAR 54.0
CC
17
Cov
11%
publish
110.0
new_from_env
20.0
new
12.0
CRAP 220.7
↑ Summary
1 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
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  
5 package Benchmark::Report::GitHub;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.001';
9  
10 1 my @attributes = qw/ travis_repo_slug gh_name gh_email gh_token /;
11  
12 sub new {
13 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
14 0 my $self = bless +{ @_ }, $class;
15 defined($self->{$_}) || die("missing required attribute: $_")
16 0 ▶ for @attributes;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$_} or die "missing required attribute: $_" 0 0 0
17 0 return $self;
18 }
19  
20 sub new_from_env {
21 0 ▶ my $class = shift;
Subroutine new_from_env: not called CC=4 SCAR=30.0
Pod documented
22
23 0 my $missing = 0;
24 0 for my $var (qw/ TRAVIS_REPO_SLUG GH_NAME GH_EMAIL GH_TOKEN /) {
25 0 ▶ next if defined $ENV{$var};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$var} 0 0 0
26 0 warn "missing: $var\n";
27 0 $missing++;
28 }
29 0 ▶ die "correct environment variables are not set; bailing out"
Branch: 1 branch
BranchTrueFalseTotal
if $missing 0 0 0
30 if $missing;
31
32 0 $class->new(map +( $_ => $ENV{uc($_)} ), @attributes);
33 }
34  
35 sub add_benchmark {
36 0 ▶ my $self = shift;
Subroutine add_benchmark: not called CC=3 SCAR=24.8
Pod documented
37 0 ▶ @_ == 3 or die("too many or too few arguments");
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or die "too many or too few arguments" 0 0 0
38 0 ▶ push @{ $self->{benchmarks} ||= [] }, @_;
Condition0%0/2
$self->{"benchmarks"} ||= []
l!l
00
MC/DC0%0/1
$self->{"benchmarks"} ||= []
$self->{"benchmarks"}
Truth table0%0/2
A
A= $self->{"benchmarks"}
Aresult
11
00
39 0 return $self;
40 }
41  
42 sub publish {
43 0 ▶ my $self = shift;
Subroutine publish: not called CC=10 SCAR=47.0
Pod documented
44 0 my %args = @_;
45
46 0 my ($owner, $project) = split "/", $self->{travis_repo_slug};
47
48 0 ▶ my @benchmarks = @{$self->{benchmarks}}
Branch: 1 branch
BranchTrueFalseTotal
my(@benchmarks) = @{$self->{"benchmarks"};} or die "did you forget something?" 0 0 0
49 or die "did you forget something?";
50
51 0 system("rm -fr $project.wiki");
52 0 system("git clone https://github.com/$owner/$project.wiki.git");
53
54 0 ▶ my $perl = $args{perl_version} || $ENV{TRAVIS_PERL_VERSION} || $];
Condition0%0/6
$args{'perl_version'} || $ENV{'TRAVIS_PERL_VERSION'} || $]
l!l&&r!l&&!r
000
$args{"perl_version"} or $ENV{"TRAVIS_PERL_VERSION"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'perl_version'} || $ENV{'TRAVIS_PERL_VERSION'} || $]
$args{"perl_version"} $ENV{"TRAVIS_PERL_VERSION"} $]
Truth table0%0/4
A or B || C
A= $args{"perl_version"}B= $ENV{"TRAVIS_PERL_VERSION"}C= $]
ABCresult
1XX1
01X1
0011
0000
55 my ($build_num, $build_id, $job_num, $job_id) = map {
56 0 ▶ $args{$_} || $ENV{ "TRAVIS_" . uc($_) } || 'unknown'
Branch: 1 branch
BranchTrueFalseTotal
$args{$_} or $ENV{'TRAVIS_' . uc($_)} or "unknown" 0 0 0
Condition0%0/3
$args{$_} or $ENV{'TRAVIS_' . uc($_)}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{$_} or $ENV{'TRAVIS_' . uc($_)}
$args{$_} $ENV{'TRAVIS_' . uc($_)}
Truth table0%0/3
A or B
A= $args{$_}B= $ENV{'TRAVIS_' . uc($_)}
ABresult
1X1
011
000
57 } qw( build_number build_id job_number job_id );
58
59 0 ▶ my $page = $args{page} || "Benchmark_$job_id";
Condition0%0/2
$args{'page'} || "Benchmark_$job_id"
l!l
00
MC/DC0%0/1
$args{'page'} || "Benchmark_$job_id"
$args{'page'}
Truth table0%0/2
A
A= $args{'page'}
Aresult
11
00
60 0 ▶ my $title = $args{page_title} || "Travis Job $job_num";
Condition0%0/2
$args{'page_title'} || "Travis Job $job_num"
l!l
00
MC/DC0%0/1
$args{'page_title'} || "Travis Job $job_num"
$args{'page_title'}
Truth table0%0/2
A
A= $args{'page_title'}
Aresult
11
00
61 0 ▶ my $idxpage = $args{index_page} || "Benchmarks";
Condition0%0/2
$args{'index_page'} || 'Benchmarks'
l!l
00
MC/DC0%0/1
$args{'index_page'} || 'Benchmarks'
$args{'index_page'}
Truth table0%0/2
A
A= $args{'index_page'}
Aresult
11
00
62
63 0 require Benchmark;
64 0 require Cwd;
65 0 require File::Path;
66
67 RESULTS: {
68 0 open my $fh, ">", "$project.wiki/$page.md";
69 0 print $fh "# $title\n\n";
70 0 print $fh "[Build log](https://travis-ci.org/$owner/$project/jobs/$job_id).\n\n";
71 0 my $old = select($fh);
72 0 ▶ while (@benchmarks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@benchmarks) 0 0 0
73 0 my ($name, $times, $cases) = splice(@benchmarks, 0, 3);
74 0 print "## $name\n\n";
75 0 print "```\n";
76 0 Benchmark::cmpthese($times, $cases);
77 0 print "```\n\n";
78 }
79 0 select($old);
80 0 close $fh;
81 }
82
83 INDEX: {
84 0 open my $idx, ">>", "$project.wiki/$idxpage.md";
85 0 print $idx "* [$title]($page)\n";
86 0 close $idx;
87 }
88
89 UPLOAD: {
90 0 my $orig = Cwd::cwd();
91 0 chdir "$project.wiki";
92 0 system("git config user.name '$ENV{GH_NAME}'");
93 0 system("git config user.email '$ENV{GH_EMAIL}'");
94 0 system("git config credential.helper 'store --file=.git/credentials'");
95 0 open my $cred, '>', '.git/credentials';
96 0 print $cred "https://$ENV{GH_TOKEN}:\@github.com\n";
97 0 close $cred;
98 0 system("git add .");
99 0 system("git commit -a -m 'benchmarks for $job_num'");
100 0 system("git push --all");
101 0 system("rm '.git/credentials'");
102 0 chdir($orig);
103 0 File::Path::remove_tree("$project.wiki");
104 }
105
106 0 return "https://github.com/$owner/$project/wiki/$page";
107 }
108  
109 1 1;
110  
111 __END__
↑ Summary