Simple/Progress.pm

filter: Statementstmt 19.5% 9 / 46 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 7 totaltotal 13.3% 12 / 90 CC 12 SCAR 31.6
CC
12
Cov
14%
reach
56.0
new
12.0
delay
6.0
CRAP 23.5
« Simple.pm ↑ Summary Simple/PullParser.pm »
1 package Pod::Simple::Progress;
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 1 our $VERSION = '3.48';
6  
7 # Objects of this class are used for noting progress of an
8 # operation every so often. Messages delivered more often than that
9 # are suppressed.
10 #
11 # There's actually nothing in here that's specific to Pod processing;
12 # but it's ad-hoc enough that I'm not willing to give it a name that
13 # implies that it's generally useful, like "IO::Progress" or something.
14 #
15 # -- sburke
16 #
17 #--------------------------------------------------------------------------
18  
19 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
20 0 my($class,$delay) = @_;
21 0 ▶ my $self = bless {'quiet_until' => 1}, ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
22 0 $self->to(*STDOUT{IO});
23 0 ▶ $self->delay(defined($delay) ? $delay : 5);
Branch: 1 branch
BranchTrueFalseTotal
defined $delay ? : 0 0 0
24 0 return $self;
25 }
26  
27 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $orig = shift;
29 0 bless {%$orig, 'quiet_until' => 1}, ref($orig);
30 }
31 #--------------------------------------------------------------------------
32  
33 0 ▶sub reach {
Subroutine reach: not called CC=7 SCAR=40.3
Pod undocumented
34 0 my($self, $point, $note) = @_;
35 0 ▶ if( (my $now = time) >= $self->{'quiet_until'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $now = time) >= $self->{"quiet_until"}) 0 0 0
36 0 my $goal;
37 0 my $to = $self->{'to'};
38 print $to join('',
39 ($self->{'quiet_until'} == 1) ? () : '... ',
40 (defined $point) ? (
41 '#',
42 0 ▶ ($goal = $self->{'goal'}) ? (
Branch: 4 branches
BranchTrueFalseTotal
$self->{'quiet_until'} == 1 ? : 0 0 0
defined $point ? : 0 0 0
($goal = $self->{'goal'}) ? : 0 0 0
$note ? : 0 0 0
Condition0%0/2
$note || ''
l!l
00
MC/DC0%0/1
$note || ''
$note
Truth table0%0/2
A
A= $note
Aresult
11
00
43 ' ' x (length($goal) - length($point)),
44 $point, '/', $goal,
45 ) : $point,
46 $note ? ': ' : (),
47 ) : (),
48 $note || '',
49 "\n"
50 );
51 0 $self->{'quiet_until'} = $now + $self->{'delay'};
52 }
53 0 return $self;
54 }
55  
56 #--------------------------------------------------------------------------
57  
58 0 ▶sub done {
Subroutine done: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my($self, $note) = @_;
60 0 $self->{'quiet_until'} = 1;
61 0 return $self->reach( undef, $note );
62 }
63  
64 #--------------------------------------------------------------------------
65 # Simple accessors:
66  
67 0 ▶sub delay {
Subroutine delay: not called CC=2 SCAR=17.9
Pod undocumented
68 0 ▶ return $_[0]{'delay'} if @_ == 1; $_[0]{'delay'} = $_[1]; return $_[0] }
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
69 0 ▶sub goal {
Subroutine goal: not called CC=2 SCAR=17.9
Pod undocumented
70 0 ▶ return $_[0]{'goal' } if @_ == 1; $_[0]{'goal' } = $_[1]; return $_[0] }
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
71 0 ▶sub to {
Subroutine to: not called CC=2 SCAR=17.9
Pod undocumented
72 0 ▶ return $_[0]{'to' } if @_ == 1; $_[0]{'to' } = $_[1]; return $_[0] }
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
73  
74 #--------------------------------------------------------------------------
75  
76 1 ▶unless(caller) { # Simple self-test:
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
77 0 my $p = __PACKAGE__->new->goal(5);
78 0 $p->reach(1, "Primus!");
79 0 sleep 1;
80 0 $p->reach(2, "Secundus!");
81 0 sleep 3;
82 0 $p->reach(3, "Tertius!");
83 0 sleep 5;
84 0 $p->reach(4);
85 0 $p->reach(5, "Quintus!");
86 0 sleep 1;
87 0 $p->done("All done");
88 }
89  
90 #--------------------------------------------------------------------------
91 1 1;
92 __END__
« Simple.pm ↑ Summary Simple/PullParser.pm »