File Coverage

blib/lib/IPC/Run3/ProfLogReader.pm
Criterion Covered Total %
statement 32 40 80.0
branch 12 20 60.0
condition 6 12 50.0
subroutine 4 6 66.6
pod 5 5 100.0
total 59 83 71.0


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