lib/BeamerReveal/Log.pm

filter: Statementstmt 19.4% 15 / 77 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 28.5% 4 / 14 Podpod 37.5% 3 / 8 totaltotal 15.4% 22 / 142 CC 16 SCAR 33.0
CC
16
Cov
14%
new
72.0
registerTask
20.0
_formatLines
20.0
CRAP 27.2
« lib/BeamerReveal/MediaManager.pm ↑ Summary lib/BeamerReveal/IPC/Run.pm »
1 # -*- cperl -*-
2 # ABSTRACT: Log
3  
4  
5 package BeamerReveal::Log;
6 1 our $VERSION = '20261115.1249'; # VERSION
7  
8 1 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use BeamerReveal::Log::Ansi;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our $logger;
16  
17 0 ▶sub max { $_[$_[0] < $_[1] ] }
Subroutine max: not called CC=1 SCAR=6.9
Pod undocumented
18  
19  
20  
21 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
22 0 ▶ $logger->fatal( "Error: internal error - attempt to create two logger objects\n" )
Branch: 1 branch
BranchTrueFalseTotal
if defined $logger 0 0 0
23 if ( defined( $logger ) );
24 0 my $class = shift;
25 0 my $args = { @_ };
26 exists $args->{logfilename}
27 and exists $args->{opening}
28 and exists $args->{closing}
29 and exists $args->{labelsize}
30 and exists $args->{activitysize}
31 0 ▶ or die( "Error: missing argument to (child of) BeamerReveal::Log::new()\n" );
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"logfilename"} and exists $args->{"opening"} and exists $args->{"closing"} and exists $args->{"labelsize"} and exists $args->{"activitysize"} or die "Error: missing argument to (child of) BeamerReveal::Log::new()\n" 0 0 0
Condition0%0/12
exists $args->{"logfilename"} and exists $args->{"opening"} and exists $args->{"closing"} and exists $args->{"labelsize"} and exists $args->{"activitysize"}
!ll&&!rl&&r
000
exists $args->{"logfilename"} and exists $args->{"opening"} and exists $args->{"closing"} and exists $args->{"labelsize"}
!ll&&!rl&&r
000
exists $args->{"logfilename"} and exists $args->{"opening"} and exists $args->{"closing"}
!ll&&!rl&&r
000
exists $args->{"logfilename"} and exists $args->{"opening"}
!ll&&!rl&&r
000
MC/DC0%0/5
exists $args->{"logfilename"} and exists $args->{"opening"} and exists $args->{"closing"} and exists $args->{"labelsize"} and exists $args->{"activitysize"}
exists $args->{"logfilename"} exists $args->{"opening"} exists $args->{"closing"} exists $args->{"labelsize"} exists $args->{"activitysize"}
Truth table0%0/6
A and B and C and D and E
A= exists $args->{"logfilename"}B= exists $args->{"opening"}C= exists $args->{"closing"}D= exists $args->{"labelsize"}E= exists $args->{"activitysize"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
32 0 my $self = BeamerReveal::Log::Ansi->new( %$args );
33  
34 0 $self->{tasks} = [];
35  
36 0 $self->{termwidth} = $self->_terminal_width();
37 0 $self->{barsize} = $self->{termwidth} - $self->{labelsize} - $self->{activitysize} - 12;
38
39 0 $self->{logfile} = IO::File->new();
40 0 ▶ $self->{logfile}->open( ">$self->{logfilename}" )
Branch: 1 branch
BranchTrueFalseTotal
$self->{"logfile"}->open(qq[>$self->{"logfilename"}]) or die qq[Error cannot open log file $self->{"logfilename"}] 0 0 0
41 or die( "Error cannot open log file $self->{logfilename}" );
42  
43 # build opening lines for logfile
44 0 print {$self->{logfile}} _formatLines( $self->{opening}, 76 );
45 # build opening lines for terminal
46 0 print _formatLines( $self->{opening}, $self->{termwidth} );
47
48 0 $logger = $self;
49
50 0 return $self;
51 }
52  
53  
54 0 ▶sub log {
Subroutine log: not called CC=1 SCAR=6.9
Pod documented
55 0 my $self = shift;
56 0 my ( $indent, $message ) = @_;
57  
58 0 say {$self->{logfile}} ( ' ' x $indent ) . $message;
59 }
60  
61 0 ▶sub fatal {
Subroutine fatal: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $self = shift;
63 0 my ( $message ) = @_;
64  
65 0 say {$self->{logfile}} $message;
66 0 $self->{logfile}->close();
67
68 0 die( "$message\n" .
69 "Check the logfile $self->{logfilename} for more information.\n" );
70 }
71  
72  
73 0 ▶sub registerTask {
Subroutine registerTask: not called CC=4 SCAR=30.0
Pod documented
74 0 my $self = shift;
75 0 my $args = { @_ };
76 exists $args->{label}
77 and exists $args->{progress}
78 and exists $args->{total}
79 0 ▶ or $self->fatal( "Error: missing argument to BeamerReveal::Log::registerTask\n" );
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"label"} and exists $args->{"progress"} and exists $args->{"total"} or $self->fatal("Error: missing argument to BeamerReveal::Log::registerTask\n") 0 0 0
Condition0%0/6
exists $args->{"label"} and exists $args->{"progress"} and exists $args->{"total"}
!ll&&!rl&&r
000
exists $args->{"label"} and exists $args->{"progress"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $args->{"label"} and exists $args->{"progress"} and exists $args->{"total"}
exists $args->{"label"} exists $args->{"progress"} exists $args->{"total"}
Truth table0%0/4
A and B and C
A= exists $args->{"label"}B= exists $args->{"progress"}C= exists $args->{"total"}
ABCresult
0XX0
10X0
1100
1111
80 # fill out default value for activity message
81 0 $args->{activity} = '';
82
83 0 my $index = @{$self->{tasks}};
84 0 push @{$self->{tasks}}, $args;
85 0 return $index;
86 }
87  
88 0 ▶sub activate {
Subroutine activate: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my $self = shift;
90 0 $self->fatal( "Error: internal error - activation through BeamerReveal::Log base class\n" );
91 }
92  
93 0 ▶sub progress {
Subroutine progress: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my $self = shift;
95 0 $self->fatal( "Error: internal error - progress reported through BeamerReveal::Log base class\n" );
96 }
97  
98 0 ▶sub finalize {
Subroutine finalize: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my $self = shift;
100 0 $self->fatal( "Error: internal error - finalization through BeamerReveal::Log base class\n" );
101 }
102  
103 0 ▶sub _bar_line {
Subroutine _bar_line: not called CC=3 SCAR=24.8
104 0 my ($label, $labelsize, $activity, $activitysize, $done, $total, $width) = @_;
105
106 0 my $pct = $done / $total;
107 0 ▶ $pct = 1 if $pct > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $pct > 1 0 0 0
108
109 0 my $filled = int($pct * $width);
110 0 my $empty = $width - $filled;
111  
112 0 ▶ if ( $width < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width < 0) { } 0 0 0
113 0 return sprintf("%s: %s / %5.1f%%",
114 $label,
115 $activity,
116 $pct * 100
117 );
118 }
119 else {
120 0 return sprintf("%-${labelsize}s: %-${activitysize}s [%s%s] %5.1f%%",
121 $label,
122 $activity,
123 '#' x $filled,
124 '-' x $empty,
125 $pct * 100
126 );
127 }
128 }
129  
130 0 ▶sub _formatLines {
Subroutine _formatLines: not called CC=4 SCAR=30.0
131 0 my ( $linearrayref, $width, $extra ) = @_;
132 0 ▶ $extra ||= '';
Condition0%0/2
$extra ||= ""
l!l
00
MC/DC0%0/1
$extra ||= ""
$extra
Truth table0%0/2
A
A= $extra
Aresult
11
00
133 0 my $openinglines;
134 0 foreach my $line ( @{$linearrayref} ) {
135 0 my ( $left, $right) = split( /\|/, $line );
136 0 ▶ if( $left eq $right ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left eq $right) { } 0 0 0
137 0 $openinglines .= $extra . ( $left x $width ) . "\n";
138 }
139 else {
140 0 my $llen = length( $left );
141 0 my $rlen = length( $right );
142 0 my $midspace = max( 1, $width - $llen - $rlen );
143 0 $openinglines .= $extra . $left . ( ' ' x $midspace ) . $right . "\n";
144 }
145 }
146 0 return $openinglines;
147 }
148 1 1;
149  
150 __END__
« lib/BeamerReveal/MediaManager.pm ↑ Summary lib/BeamerReveal/IPC/Run.pm »