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