Run3/ProfLogReader.pm

filter: Statementstmt 80.9% 34 / 42 Branchbran 63.6% 14 / 22 Conditioncond 50.0% 6 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 66.6% 4 / 6 Podpod 100% 5 / 5 totaltotal 68.0% 64 / 94 CC 16 SCAR 23.4
CC
16
Cov
71%
new
18.0
read
8.3
set_handler
2.0
CRAP 10.4
« Run3/ProfLogger.pm ↑ Summary Run3/ProfReporter.pm »
1 package IPC::Run3::ProfLogReader;
2  
3 1 $VERSION = 0.048;
4  
5 =head1 NAME
6  
7 IPC::Run3::ProfLogReader - read and process a ProfLogger file
8  
9 =head1 SYNOPSIS
10  
11 use IPC::Run3::ProfLogReader;
12  
13 my $reader = IPC::Run3::ProfLogReader->new; ## use "run3.out"
14 my $reader = IPC::Run3::ProfLogReader->new( Source => $fn );
15  
16 my $profiler = IPC::Run3::ProfPP; ## For example
17 my $reader = IPC::Run3::ProfLogReader->new( ..., Handler => $p );
18  
19 $reader->read;
20 $eaderr->read_all;
21  
22 =head1 DESCRIPTION
23  
24 Reads a log file. Use the filename "-" to read from STDIN.
25  
26 =cut
27  
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 =head1 METHODS
31  
32 =head2 C<< IPC::Run3::ProfLogReader->new( ... ) >>
33  
34 =cut
35  
36 sub new {
37 1 ▶ my $class = ref $_[0] ? ref shift : shift;
Subroutine new: called CC=8 SCAR=28.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
38 1 my $self = bless { @_ }, $class;
39
40 $self->{Source} = "run3.out"
41 1 ▶ unless defined $self->{Source} && length $self->{Source};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Source"} and length $self->{"Source"} 0 1 1
Condition33%1/3
defined $self->{"Source"} and length $self->{"Source"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"Source"} and length $self->{"Source"}
defined $self->{"Source"} length $self->{"Source"}
Truth table33%1/3
A and B
A= defined $self->{"Source"}B= length $self->{"Source"}
ABresult
0X0
100
111
42  
43 1 my $source = $self->{Source};
44  
45 1 ▶ if ( ref $source eq "GLOB" || UNIVERSAL::isa( $source, "IO::Handle" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $source eq 'GLOB' or UNIVERSAL::isa($source, 'IO::Handle')) { } 1 0 1
elsif ($source eq '-') { } 0 0 0
Condition33%1/3
ref $source eq "GLOB" or UNIVERSAL::isa($source, "IO::Handle")
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $source eq "GLOB" or UNIVERSAL::isa($source, "IO::Handle")
ref $source eq "GLOB" UNIVERSAL::isa($source, "IO::Handle")
Truth table33%1/3
A or B
A= ref $source eq "GLOB"B= UNIVERSAL::isa($source, "IO::Handle")
ABresult
1X1
011
000
46 1 $self->{FH} = $source;
47 }
48 elsif ( $source eq "-" ) {
49 0 $self->{FH} = \*STDIN;
50 }
51 else {
52 0 ▶ open PROFILE, "<$self->{Source}" or die "$!: $self->{Source}\n";
Branch: 1 branch
BranchTrueFalseTotal
open PROFILE, qq[<$self->{"Source"}] or die qq[$!: $self->{"Source"}\n] 0 0 0
53 0 $self->{FH} = *PROFILE{IO};
54 }
55 1 return $self;
56 }
57  
58  
59 =head2 C<< $reader->set_handler( $handler ) >>
60  
61 =cut
62  
63 0 ▶sub set_handler { $_[0]->{Handler} = $_[1] }
Subroutine set_handler: not called CC=1 SCAR=6.9
Pod documented
64  
65 =head2 C<< $reader->get_handler() >>
66  
67 =cut
68  
69 0 ▶sub get_handler { $_[0]->{Handler} }
Subroutine get_handler: not called CC=1 SCAR=6.9
Pod documented
70  
71 =head2 C<< $reader->read() >>
72  
73 =cut
74  
75 sub read {
76 5 ▶ my $self = shift;
Subroutine read: called CC=8 SCAR=21.1
Pod documented
77  
78 5 my $fh = $self->{FH};
79 5 my @ln = split / /, <$fh>;
80  
81 5 ▶ return 0 unless @ln;
Branch: 1 branch
BranchTrueFalseTotal
unless @ln 1 4 5
82 4 ▶ return 1 unless $self->{Handler};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Handler"} 0 4 4
83  
84 4 chomp $ln[-1];
85  
86 ## Ignore blank and comment lines.
87 4 ▶ return 1 if @ln == 1 && ! length $ln[0] || 0 == index $ln[0], "#";
Branch: 1 branch
BranchTrueFalseTotal
if @ln == 1 and not length $ln[0] or 0 == index($ln[0], "#") 1 3 4
Condition66%4/6
@ln == 1 and not length $ln[0] or 0 == index($ln[0], "#")
l!l&&r!l&&!r
103
@ln == 1 and not length $ln[0]
!ll&&!rl&&r
301
MC/DC33%1/3
@ln == 1 and not length $ln[0] or 0 == index($ln[0], "#")
@ln == 1 not length $ln[0] 0 == index($ln[0], "#")
Truth table40%2/5
A and not(B) or C
A= @ln == 1B= not length $ln[0]C= 0 == index($ln[0], "#")
ABCresult
11X1
0X11
1011
0X00
1000
88  
89 3 ▶ if ( $ln[0] eq "\\app_call" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ln[0] eq '\\app_call') { } 1 2 3
elsif ($ln[0] eq '\\app_exit') { } 1 1 2
90 1 shift @ln;
91 1 my @times = split /,/, pop @ln;
92 $self->{Handler}->app_call(
93 [
94 map {
95 1 s/\\\\/\\/g;
96 0 s/\\_/ /g;
97 0 $_;
98 } @ln
99 ],
100 @times
101 );
102 }
103 elsif ( $ln[0] eq "\\app_exit" ) {
104 1 shift @ln;
105 1 $self->{Handler}->app_exit( pop @ln, @ln );
106 }
107 else {
108 1 my @times = split /,/, pop @ln;
109 $self->{Handler}->run_exit(
110 [
111 map {
112 1 s/\\\\/\\/g;
113 2 s/\\_/ /g;
114 2 $_;
115 } @ln
116 ],
117 @times
118 );
119 }
120  
121 3 return 1;
122 }
123  
124  
125 =head2 C<< $reader->read_all() >>
126  
127 This method reads until there is nothing left to read, and then returns true.
128  
129 =cut
130  
131 sub read_all {
132 1 ▶ my $self = shift;
Subroutine read_all: called CC=2 SCAR=6.9
Pod documented
133  
134 1 ▶ 1 while $self->read;
Branch: 1 branch
BranchTrueFalseTotal
$self->read and do { '???' } 3 1 4
135  
136 1 return 1;
137 }
138  
139  
140 =head1 LIMITATIONS
141  
142 =head1 COPYRIGHT
143  
144 Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
145  
146 =head1 LICENSE
147  
148 You may use this module under the terms of the BSD, Artistic, or GPL licenses,
149 any version.
150  
151 =head1 AUTHOR
152  
153 Barrie Slaymaker E<lt>barries@slaysys.comE<gt>
154  
155 =cut
156  
157 1 1;
« Run3/ProfLogger.pm ↑ Summary Run3/ProfReporter.pm »