| 1 | package Carmel::ProgressBar; | ||||||||||||||||||||||||||||
| 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 | ▶ | use Class::Tiny qw( quiet width total _prev ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use POSIX qw(ceil); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT = qw(progress); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub progress { | ||||||||||||||||||||||||||
|
Subroutine
progress: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 0 | my($args, $code) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | return unless @$args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | my $class = __PACKAGE__; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $self = $class->new( | |||||||||||||||||||||||||||
| 19 | width => 40, | ||||||||||||||||||||||||||||
| 20 | total => scalar(@$args), | ||||||||||||||||||||||||||||
| 21 | quiet => !-t STDOUT, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | local $| = 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | unless $self->quiet; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | $self->update(0); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | for my $i (0..$#$args) { | |||||||||||||||||||||||||||
| 30 | 0 | $code->($args->[$i]); | |||||||||||||||||||||||||||
| 31 | 0 | $self->update($i+1); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | $self->clear; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | my($self, $count) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $width = $self->width; | |||||||||||||||||||||||||||
| 43 | 0 | my $done = ceil($count * $width / $self->total); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $head = $width == $done ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | my $remain = ($width - $done - $head); | |||||||||||||||||||||||||||
| 46 | 0 | my $len = length $self->total; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $line = sprintf "[%s%s%s] %${len}d/%d", | |||||||||||||||||||||||||||
| 49 | ("=" x $done), (">" x $head), (" " x $remain), | ||||||||||||||||||||||||||||
| 50 | $count, $self->total; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return if $self->_prev && $line eq $self->_prev; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_prev and $line eq $self->_prev
MC/DC0%0/2
$self->_prev and $line eq $self->_prev
$self->_prev
$line eq $self->_prev
Truth table0%0/3
A and B
A= $self->_prevB= $line eq $self->_prev
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | print "\r", $line; | |||||||||||||||||||||||||||
| 55 | 0 | $self->_prev($line); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | return; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | print "\r", " " x ($self->width + 2*length($self->total) + 4), "\r"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | 1; | |||||||||||||||||||||||||||