| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package IPC::Run3::ProfLogReader; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = 0.049; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | IPC::Run3::ProfLogReader - read and process a ProfLogger file | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | use IPC::Run3::ProfLogReader; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | my $reader = IPC::Run3::ProfLogReader->new; ## use "run3.out" | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | my $reader = IPC::Run3::ProfLogReader->new( Source => $fn ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $profiler = IPC::Run3::ProfPP; ## For example | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | my $reader = IPC::Run3::ProfLogReader->new( ..., Handler => $p ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | $reader->read; | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $eaderr->read_all; | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Reads a log file. Use the filename "-" to read from STDIN. | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =head2 C<< IPC::Run3::ProfLogReader->new( ... ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $self = bless { @_ }, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->{Source} = "run3.out" | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | unless defined $self->{Source} && length $self->{Source}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"Source"} and length $self->{"Source"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $source = $self->{Source}; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( ref $source eq "GLOB" || UNIVERSAL::isa( $source, "IO::Handle" ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $source eq "GLOB" or UNIVERSAL::isa($source, "IO::Handle")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | my $fh = $self->{FH}; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | my $ln = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | my @ln = defined $ln ? (split / /, $ln) : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | return 0 unless @ln; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | return 1 unless $self->{Handler}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | chomp $ln[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ## Ignore blank and comment lines. | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | return 1 if @ln == 1 && ! length $ln[0] || 0 == index $ln[0], "#"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@ln == 1 and not length $ln[0] or 0 == index($ln[0], "#")
@ln == 1 and not length $ln[0]
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], "#")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | if ( $ln[0] eq "\\app_call" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | shift @ln; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my @times = split /,/, pop @ln; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | $self->{Handler}->app_call( | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | s/\\\\/\\/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | s/\\_/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } @ln | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | @times | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | elsif ( $ln[0] eq "\\app_exit" ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | shift @ln; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $self->{Handler}->app_exit( pop @ln, @ln ); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my @times = split /,/, pop @ln; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | $self->{Handler}->run_exit( | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | s/\\\\/\\/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | s/\\_/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } @ln | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | @times | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =head2 C<< $reader->read_all() >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | This method reads until there is nothing left to read, and then returns true. | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub read_all { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_all: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | 1 while $self->read; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | You may use this module under the terms of the BSD, Artistic, or GPL licenses, | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | any version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Barrie Slaymaker E<lt>barries@slaysys.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||