| 1 | package Liveman::CoverBadge; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use common::sense; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use File::Basename qw/dirname/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use File::Slurper qw/read_text write_text/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use File::Path qw/mkpath/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # Конструктор | ||||||||||||||||||||
| 9 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||
| 10 | 1 | my $cls = shift; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | bless { | ||||||||||||||||||
|
Condition33%1/3
ref $cls || $cls
MC/DC0%0/2
ref $cls || $cls
ref $cls
$cls
Truth table33%1/3
A || B
A= ref $clsB= $cls
| |||||||||||||||||||||
| 13 | coverage_html => 'cover_db/coverage.html', | ||||||||||||||||||||
| 14 | badge_path => 'doc/badges/total.svg', | ||||||||||||||||||||
| 15 | template => << 'END', | ||||||||||||||||||||
| 16 | <?xml version="1.0"?> | ||||||||||||||||||||
| 17 | <svg xmlns="http://www.w3.org/2000/svg" width="112" height="20"><linearGradient id="smooth" x2="0" y2="100%"><stop stop-opacity=".1" offset="0" stop-color="#bbb"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="round"><rect width="112" rx="3" height="20" fill="#fff"/></clipPath><g clip-path="url(#round)"><rect width="65" fill="$FILL" height="20"/><rect width="47" x="65" fill="$COLOR" height="20"/><rect width="112" fill="url(#smooth)" height="20"/></g><g font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11" fill="#fff" text-anchor="middle"><text y="15" fill="#010101" x="33.5" fill-opacity=".3">$LEFT</text><text y="14" x="33.5">$LEFT</text><text x="87.5" fill-opacity=".3" fill="#010101" y="15">$RIGHT</text><text y="14" x="87.5">$RIGHT</text></g></svg> | ||||||||||||||||||||
| 18 | END | ||||||||||||||||||||
| 19 | @_ | ||||||||||||||||||||
| 20 | }, ref $cls || $cls; | ||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # Создаёт svg | ||||||||||||||||||||
| 24 | 0 | ▶ | sub svg { | ||||||||||||||||||
|
Subroutine
svg: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | 0 | my ($self, $percentage) = @_; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | ▶ | my $color = $percentage >= 90 ? '#00FA9A' : | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 28 | $percentage >= 80 ? '#ADFF2F' : | ||||||||||||||||||||
| 29 | $percentage >= 70 ? '#FFFF00' : '#DC143C'; | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | my $svg = $self->{template}; | |||||||||||||||||||
| 32 | 0 | $svg =~ s/\$LEFT/coverage/g; | |||||||||||||||||||
| 33 | 0 | $svg =~ s/\$RIGHT/$percentage%/g; | |||||||||||||||||||
| 34 | 0 | $svg =~ s/\$COLOR/$color/g; | |||||||||||||||||||
| 35 | 0 | $svg =~ s/\$FILL/#24292E/g; | |||||||||||||||||||
| 36 | 0 | $svg | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # Загружает покрытие из отчёта html | ||||||||||||||||||||
| 40 | 1 | ▶ | sub load { | ||||||||||||||||||
|
Subroutine
load: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||
| 41 | 1 | my ($self) = @_; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | my $report = read_text $self->{coverage_html}; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ($self->{coverage}) = $report =~ m!(\d+(?:\.\d+)?)\s*</td>\s*</tr>\s*</tfoot>!s; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | $self | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | # Сохраняет бэйдж | ||||||||||||||||||||
| 51 | 0 | ▶ | sub save { | ||||||||||||||||||
|
Subroutine
save: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 52 | 0 | my ($self) = @_; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | mkpath dirname $self->{badge_path}; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | write_text $self->{badge_path}, $self->svg($self->{coverage}); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | $self | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | 1; | |||||||||||||||||||