Logs/Event.pm

filter: Statementstmt 100% 37 / 37 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 72.0% 54 / 75 CC 12 SCAR 19.5
CC
12
Cov
78%
get_hash
11.4
new
4.7
BEGIN
1.0
CRAP 7.0
« Logs.pm ↑ Summary
1 package PBS::Logs::Event;
2  
3 =head1 NAME
4  
5 PBS::Logs::Event - parses the PBS event log files
6 and inherits from PBS::Logs.
7  
8 =head1 SYNOPSIS
9  
10 See the sections below:
11  
12 use PBS::Logs::Event;
13  
14 The only non-inheritable function is the class level debug()
15  
16 PBS::Logs::Event::debug()
17  
18 You must use
19  
20 PBS::Logs::debug()
21  
22 to read or set global debugging.
23 However, the instance version works just fine:
24  
25 $pl->debug()
26  
27 Other than that
28 PBS::Logs::Event inherits all the methods that are available from
29 PBS::Logs, plus adds the methods listed below.
30  
31 =head1 DESCRIPTION
32  
33 =head2 EXPORT
34  
35 None by default.
36  
37 =head1 SEE ALSO
38  
39 =over
40  
41 =item PBS::Logs
42  
43 =item PBS::Logs::Acct
44  
45 =item The PBS Pro 5.4 Administrator Guide
46  
47 =back
48  
49 =head1 AUTHOR
50  
51 Dr R K Owen, E<lt>rkowen@nersc.govE<gt>
52  
53 =head1 COPYRIGHT AND LICENSE
54  
55 Copyright (C) 2005 The Regents of the University of California
56  
57 This library is free software; you can redistribute it
58 and/or modify it under the terms of the GNU Lesser General
59 Public License as published by the Free Software Foundation;
60 either version 2.1 of the License, or (at your option) any
61 later version.
62  
63 This library is distributed in the hope that it will be useful,
64 but WITHOUT ANY WARRANTY; without even the implied warranty
65 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
66 the GNU Lesser General Public License for more details,
67 which can be found at:
68  
69 http://www.gnu.org/copyleft/lesser.html
70 or http://www.opensource.org/licenses/lgpl-license.php
71  
72 =cut
73  
74 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 11 ▶use PBS::Logs;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 11 our @ISA = qw(PBS::Logs);
81  
82 11 our $VERSION = $PBS::Logs::VERSION;
83  
84 # Preloaded methods go here.
85  
86 =head1 new
87  
88 Create a PBS::Logs::Event object.
89 It takes only one argument which is either a filename, array reference,
90 or a FILE glob reference.
91  
92 See PBS::Logs::new for examples and specifics.
93  
94 =cut
95  
96 11 our %num2keys = (
97 0 => 'datetime',
98 1 => 'event_code',
99 2 => 'server_name',
100 3 => 'object_type',
101 4 => 'object_name',
102 5 => 'message'
103 );
104  
105 11 our %keys;
106 11 $keys{$num2keys{$_}}=$_ for (keys %num2keys);
107  
108 13 ▶sub new {
Subroutine new: called CC=4 SCAR=15.5
Pod undocumented
109 13 my $proto = shift;
110 13 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0130
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
111 13 my $self = $class->SUPER::new(@_);
112 carp __PACKAGE__.": creating $self\n"
113 10 ▶ if ($SUPER::debug || $self->{'-debug'});
Branch: 1 branch
BranchTrueFalseTotal
if $SUPER::debug or $self->{"-debug"} 0 10 10
Condition33%1/3
$SUPER::debug or $self->{"-debug"}
l!l&&r!l&&!r
0010
MC/DC0%0/2
$SUPER::debug or $self->{"-debug"}
$SUPER::debug $self->{"-debug"}
Truth table33%1/3
A or B
A= $SUPER::debugB= $self->{"-debug"}
ABresult
1X1
011
000
114 10 bless ($self, $class);
115 10 return $self;
116 }
117  
118 =head1 get_hash()
119  
120 Like the PBS::Logs::Event::get() method; however, instead of returning an
121 array reference, it (obviously) returns a hash
122 where the keys are the same keys as given by %PBS::Logs::Event::keys .
123  
124 The event log entry looks like this with respect to the keys:
125 datetime;event_code;server_name;object_type;object_name;message
126  
127 If in a scalar mode it will return a hash reference else it
128 returns a hash.
129  
130 =head1 Special Arrays
131  
132 The following special associative arrays (hashes)
133 are provided by this package, which may be useful for
134 translating between arrays returned by the get() method
135 to/from hashes returned by the get_hash() method, or for
136 selecting a subset of the log entry.
137  
138 =head2 %PBS::Logs::Event::num2keys
139  
140 Relates array position (number) to the keys (or field
141 descriptions) of a get_hash() generated hash.
142  
143 %num2keys = (
144 0 => 'datetime',
145 1 => 'event_code',
146 2 => 'server_name',
147 3 => 'object_type',
148 4 => 'object_name',
149 5 => 'message'
150 );
151  
152 =head2 %PBS::Logs::Event::keys
153  
154 Relates keys (field descriptions) as used by the get_hash() method
155 to array positions (number) as returned from the get() method.
156 Essentially, just the inverse of %PBS::Logs::Event::num2keys above.
157  
158 =cut
159  
160 50 ▶sub get_hash {
Subroutine get_hash: called CC=9 SCAR=24.3
Pod undocumented
161 50 my $self = shift;
162 carp __PACKAGE__.": get_hashref $self(".join(',',@_).")\n"
163 50 ▶ if ($SUPER::debug || $self->{'-debug'});
Branch: 1 branch
BranchTrueFalseTotal
if $SUPER::debug or $self->{"-debug"} 0 50 50
Condition33%1/3
$SUPER::debug or $self->{"-debug"}
l!l&&r!l&&!r
0050
MC/DC0%0/2
$SUPER::debug or $self->{"-debug"}
$SUPER::debug $self->{"-debug"}
Truth table33%1/3
A or B
A= $SUPER::debugB= $self->{"-debug"}
ABresult
1X1
011
000
164  
165 50 my $a = $self->get();
166  
167 50 ▶ if (! defined $a) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $a) 5 45 50
168 5 ▶ return () if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 5 5
169 5 return undef;
170 }
171 45 my $h = {};
172  
173 45 $h->{$_} = $a->[$keys{$_}] for (keys %keys);
174  
175 45 ▶ return if ! defined wantarray; # just read log line
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 45 45
176 45 ▶ return (defined $h ? %$h : ()) if (wantarray); # return hash
Branch: 2 branches
BranchTrueFalseTotal
if wantarray 0 45 45
defined $h ? : 0 0 0
177 45 $h; # return hash ref
178 }
179  
180 11 1;
181 __END__
« Logs.pm ↑ Summary