File Coverage

blib/lib/IPC/Run3/ProfLogReader.pm
Criterion Covered Total %
statement 36 44 81.8
branch 14 22 63.6
condition 6 12 50.0
subroutine 5 7 71.4
pod 5 5 100.0
total 66 90 73.3


line stmt bran cond sub pod time code
1 1     1   12820 use strict;
  1         2  
  1         45  
2 1     1   6 use warnings;
  1         2  
  1         1035  
3             package IPC::Run3::ProfLogReader;
4              
5             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             sub new {
37 1 50   1 1 13 my $class = ref $_[0] ? ref shift : shift;
38 1         6 my $self = bless { @_ }, $class;
39              
40             $self->{Source} = "run3.out"
41 1 50 33     15 unless defined $self->{Source} && length $self->{Source};
42              
43 1         3 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         4 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 526 my $self = shift;
77              
78 5         10 my $fh = $self->{FH};
79 5         26 my $ln = <$fh>;
80 5 100       23 my @ln = defined $ln ? (split / /, $ln) : ();
81              
82 5 100       16 return 0 unless @ln;
83 4 50       10 return 1 unless $self->{Handler};
84              
85 4         8 chomp $ln[-1];
86              
87             ## Ignore blank and comment lines.
88 4 100 66     45 return 1 if @ln == 1 && ! length $ln[0] || 0 == index $ln[0], "#";
      66        
89              
90 3 100       12 if ( $ln[0] eq "\\app_call" ) {
    100          
91 1         2 shift @ln;
92 1         9 my @times = split /,/, pop @ln;
93             $self->{Handler}->app_call(
94             [
95             map {
96 1         7 s/\\\\/\\/g;
  0         0  
97 0         0 s/\\_/ /g;
98 0         0 $_;
99             } @ln
100             ],
101             @times
102             );
103             }
104             elsif ( $ln[0] eq "\\app_exit" ) {
105 1         3 shift @ln;
106 1         6 $self->{Handler}->app_exit( pop @ln, @ln );
107             }
108             else {
109 1         19 my @times = split /,/, pop @ln;
110             $self->{Handler}->run_exit(
111             [
112             map {
113 1         5 s/\\\\/\\/g;
  2         5  
114 2         6 s/\\_/ /g;
115 2         9 $_;
116             } @ln
117             ],
118             @times
119             );
120             }
121              
122 3         15 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             sub read_all {
133 1     1 1 69 my $self = shift;
134              
135 1         12 1 while $self->read;
136              
137 1         6 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 Ebarries@slaysys.comE
155              
156             =cut
157              
158             1;