Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / IPC / Run3 / ProfLogReader.pm
1 package IPC::Run3::ProfLogReader;
2
3 $VERSION = 0.043;
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 use strict;
29
30 =head1 METHODS
31
32 =head2 C<< IPC::Run3::ProfLogReader->new( ... ) >>
33
34 =cut
35
36 sub new {
37     my $class = ref $_[0] ? ref shift : shift;
38     my $self = bless { @_ }, $class;
39     
40     $self->{Source} = "run3.out"
41         unless defined $self->{Source} && length $self->{Source};
42
43     my $source = $self->{Source};
44
45     if ( ref $source eq "GLOB" || UNIVERSAL::isa( $source, "IO::Handle" ) ) {
46         $self->{FH} = $source;
47     }
48     elsif ( $source eq "-" ) {
49         $self->{FH} = \*STDIN;
50     }
51     else {
52         open PROFILE, "<$self->{Source}" or die "$!: $self->{Source}\n";
53         $self->{FH} = *PROFILE{IO};
54     }
55     return $self;
56 }
57
58
59 =head2 C<< $reader->set_handler( $handler ) >>
60
61 =cut
62
63 sub set_handler { $_[0]->{Handler} = $_[1] }
64
65 =head2 C<< $reader->get_handler() >>
66
67 =cut
68
69 sub get_handler { $_[0]->{Handler} }
70
71 =head2 C<< $reader->read() >>
72
73 =cut
74
75 sub read {
76     my $self = shift;
77
78     my $fh = $self->{FH};
79     my @ln = split / /, <$fh>;
80
81     return 0 unless @ln;
82     return 1 unless $self->{Handler};
83
84     chomp $ln[-1];
85
86     ## Ignore blank and comment lines.
87     return 1 if @ln == 1 && ! length $ln[0] || 0 == index $ln[0], "#";
88
89     if ( $ln[0] eq "\\app_call" ) {
90         shift @ln;
91         my @times = split /,/, pop @ln;
92         $self->{Handler}->app_call(
93             [
94                 map {
95                     s/\\\\/\\/g;
96                     s/\\_/ /g;
97                     $_;
98                 } @ln
99             ],
100             @times
101         );
102     }
103     elsif ( $ln[0] eq "\\app_exit" ) {
104         shift @ln;
105         $self->{Handler}->app_exit( pop @ln, @ln );
106     }
107     else {
108         my @times = split /,/, pop @ln;
109         $self->{Handler}->run_exit(
110             [
111                 map {
112                     s/\\\\/\\/g;
113                     s/\\_/ /g;
114                     $_;
115                 } @ln
116             ],
117             @times
118         );
119     }
120
121     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     my $self = shift;
133
134     1 while $self->read;
135
136     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;