TablePrint/ProgressBar.pm

filter: Statementstmt 42.2% 19 / 45 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 32.4% 25 / 77 CC 8 SCAR 28.7
CC
8
Cov
32%
set_progress_bar
42.0
new
6.0
update_progress_bar
6.0
CRAP 17.6
« TablePrint.pm ↑ Summary
1 package Term::TablePrint::ProgressBar;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.183';
8  
9 1 ▶use Term::Choose::Constants qw( EXTRA_W );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Term::Choose::Screen qw( clear_screen clear_to_end_of_line );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Term::Choose::Util qw( get_term_width );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my ( $class, $self ) = @_;
16 0 bless $self, $class;
17 0 ▶ $self->{show_progress_bar} //= 1;
Condition0%0/2
$self->{"show_progress_bar"} //= 1
l!l
00
MC/DC0%0/1
$self->{"show_progress_bar"} //= 1
$self->{"show_progress_bar"}
Truth table0%0/2
A
A= $self->{"show_progress_bar"}
Aresult
11
00
18 0 return $self;
19 }
20  
21 0 ▶sub set_progress_bar {
Subroutine set_progress_bar: not called CC=6 SCAR=37.4
Pod undocumented
22 0 my ( $self ) = @_;
23 0 my $term_w = get_term_width() + EXTRA_W;
24 0 $self->{fmt} = "\rComputing: %3d%% [%s]";
25 0 ▶ if ( $term_w < 25 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term_w < 25) { } 0 0 0
26 0 $self->{short_print} = 1;
27 0 $self->{bar_w} = $term_w
28 }
29 else {
30 0 $self->{short_print} = 0;
31 0 $self->{bar_w} = $term_w - length( sprintf $self->{fmt}, 100, '' ) + 1; # +1: lenght("\r") == 1
32 }
33 0 ▶ $self->{step} = int( $self->{total} / $self->{bar_w} || 1 );
Condition0%0/2
$self->{'total'} / $self->{'bar_w'} || 1
l!l
00
MC/DC0%0/1
$self->{'total'} / $self->{'bar_w'} || 1
$self->{'total'} / $self->{'bar_w'}
Truth table0%0/2
A
A= $self->{'total'} / $self->{'bar_w'}
Aresult
11
00
34 0 ▶ $self->{count} //= 0;
Condition0%0/2
$self->{"count"} //= 0
l!l
00
MC/DC0%0/1
$self->{"count"} //= 0
$self->{"count"}
Truth table0%0/2
A
A= $self->{"count"}
Aresult
11
00
35 0 ▶ $self->{next_update} ||= $self->{step};
Condition0%0/3
$self->{"next_update"} ||= $self->{"step"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"next_update"} ||= $self->{"step"}
$self->{"next_update"} $self->{"step"}
Truth table0%0/3
A ||= B
A= $self->{"next_update"}B= $self->{"step"}
ABresult
1X1
011
000
36 0 ▶ if ( ! $self->{count} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"count"}) 0 0 0
37 0 print clear_screen;
38 0 print "\rComputing: ";
39 }
40 0 return;
41 }
42  
43  
44 0 ▶sub update_progress_bar {
Subroutine update_progress_bar: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my ( $self ) = @_;
46 0 my $multi = int( $self->{count} / ( $self->{total} / $self->{bar_w} ) );
47 0 ▶ if ( $self->{short_print} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'short_print'}) { } 0 0 0
48 0 print "\r", clear_to_end_of_line;
49 0 print( ( '=' x $multi ) . ( ' ' x ( $self->{bar_w} - $multi ) ) );
50 }
51 else {
52 0 printf $self->{fmt}, ( $self->{count} / $self->{total} * 100 ), ( '=' x $multi ) . ( ' ' x ( $self->{bar_w} - $multi ) );
53 }
54 0 $self->{next_update} += $self->{step};
55 }
56  
57  
58  
59  
60  
61 =pod
62  
63 =encoding UTF-8
64  
65 =head1 NAME
66  
67 Term::TablePrint::ProgressBar - Show a progress bar.
68  
69 =head1 VERSION
70  
71 Version 0.183
72  
73 =cut
74  
75 =head1 DESCRIPTION
76  
77 Provides the progress bar used in C<Term::TablePrint>.
78  
79 =head1 AUTHOR
80  
81 Matthäus Kiem <cuer2s@gmail.com>
82  
83 =head1 LICENSE AND COPYRIGHT
84  
85 Copyright 2013-2026 Matthäus Kiem.
86  
87 This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For
88 details, see the full text of the licenses in the file LICENSE.
89  
90 =cut
91  
92  
93  
94 1 1;
95  
96 __END__
« TablePrint.pm ↑ Summary