blib/lib/UMLS/Interface/ErrorHandler.pm

filter: Statementstmt 37.6% 32 / 85 Branchbran 0.0% 0 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 1 totaltotal 30.1% 38 / 126 SCAR 47.2
CC
16
Cov
28%
_error
182.0
_checkDbError
6.0
_validCui
6.0
CRAP 112.2
« blib/lib/UMLS/Interface.pm ↑ Summary utils/getCuiDef.pl »
1 # UMLS::Interface::ErrorHandler
2 # (Last Updated $Id: ErrorHandler.pm,v 1.9 2011/05/10 20:59:43 btmcinnes Exp $)
3 #
4 # Perl module that provides a perl interface to the
5 # Unified Medical Language System (UMLS)
6 #
7 # Copyright (c) 2004-2010,
8 #
9 # Bridget T. McInnes, University of Minnesota, Twin Cities
10 # bthomson at cs.umn.edu
11 #
12 # Siddharth Patwardhan, University of Utah, Salt Lake City
13 # sidd at cs.utah.edu
14 #
15 # Serguei Pakhomov, University of Minnesota, Twin Cities
16 # pakh0002 at umn.edu
17 #
18 # Ted Pedersen, University of Minnesota, Duluth
19 # tpederse at d.umn.edu
20 #
21 # Ying Liu, University of Minnesota, Twin Cities
22 # liux0935 at umn.edu
23 #
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License
26 # as published by the Free Software Foundation; either version 2
27 # of the License, or (at your option) any later version.
28 #
29 # This program is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details.
33 #
34 # You should have received a copy of the GNU General Public License
35 # along with this program; if not, write to
36 #
37 # The Free Software Foundation, Inc.,
38 # 59 Temple Place - Suite 330,
39 # Boston, MA 02111-1307, USA.
40  
41 package UMLS::Interface::ErrorHandler;
42  
43 58 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 58 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 58 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 58 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 58 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 # Errors and their error codes
50 58 my $e1 = "Database error (Error Code 1).";
51 58 my $e2 = "Self is undefined (Error Code 2).";
52 58 my $e3 = "A db is required (Error Code 3).";
53 58 my $e4 = "Undefined input value (Error Code 4).";
54 58 my $e5 = "Configuration file error (Error Code 5).";
55 58 my $e6 = "Invalid CUI (Error Code 6).";
56 58 my $e7 = "UMLS Database Content Error (Error Code 7).";
57 58 my $e8 = "UMLS Package Error (Error Code 8).";
58 58 my $e9 = "Index Error (Error Code 9).";
59 58 my $e10 = "Option Error (Error Code 10).";
60 58 my $e11 = "Unsupported Option Error (Error Code 11).";
61 58 my $e12 = "Invalid TUI (Error Code 12).";
62  
63 # throws an error and exits the program
64 # input : $pkg <- package the error originated
65 # $function <- function the error originated
66 # $string <- error message
67 # $errorcode <- error code
68 # output:
69 sub _error {
70  
71 0 ▶ my $self = shift;
Subroutine _error: not called CC=13 SCAR=52.0
72 0 my $pkg = shift;
73 0 my $function = shift;
74 0 my $string = shift;
75 0 my $errorcode = shift;
76
77 0 my $errorstring = "";
78  
79 0 ▶ if($errorcode eq 1) { $errorstring = $e1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 1) 0 0 0
80 0 ▶ if($errorcode eq 2) { $errorstring = $e2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 2) 0 0 0
81 0 ▶ if($errorcode eq 3) { $errorstring = $e3; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 3) 0 0 0
82 0 ▶ if($errorcode eq 4) { $errorstring = $e4; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 4) 0 0 0
83 0 ▶ if($errorcode eq 5) { $errorstring = $e5; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 5) 0 0 0
84 0 ▶ if($errorcode eq 6) { $errorstring = $e6; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 6) 0 0 0
85 0 ▶ if($errorcode eq 7) { $errorstring = $e7; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 7) 0 0 0
86 0 ▶ if($errorcode eq 8) { $errorstring = $e8; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 8) 0 0 0
87 0 ▶ if($errorcode eq 9) { $errorstring = $e9; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 9) 0 0 0
88 0 ▶ if($errorcode eq 10) { $errorstring = $e10; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 10) 0 0 0
89 0 ▶ if($errorcode eq 11) { $errorstring = $e11; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 11) 0 0 0
90 0 ▶ if($errorcode eq 12) { $errorstring = $e12; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 12) 0 0 0
91  
92 0 print STDERR "ERROR: $pkg->$function\n";
93 0 print STDERR "$errorstring\n";
94 0 print STDERR "$string\n";
95  
96 0 exit;
97 }
98  
99 # checks the database for an error
100 # input : $pkg => the Finder program
101 # $function => the function in the finder program
102 # $db => the database handler
103 # output:
104 sub _checkDbError {
105  
106 0 ▶ my $self = shift;
Subroutine _checkDbError: not called CC=2 SCAR=17.9
107 0 my $pkg = shift;
108 0 my $function = shift;
109 0 my $db = shift;
110  
111 0 my $errorcode = 1;
112
113 0 ▶ if($db->err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db->err) { } 0 0 0
114 0 my $errstring = "Error executing database query: $db->errstr()).";
115 0 $self->_error($pkg, $function, $errstring, $errorcode);
116 }
117 else {
118 0 return;
119 }
120 }
121  
122 # subroutine to check if CUI is valid
123 # input : $concept <- string containing a cui
124 # output: true | false <- integer indicating if the cui is valid
125 sub _validCui {
126  
127 0 ▶ my $self = shift;
Subroutine _validCui: not called CC=2 SCAR=17.9
128 0 my $concept = shift;
129
130 0 ▶ if($concept=~/C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) { } 0 0 0
131 0 return 1;
132 }
133 else {
134 0 return 0;
135 }
136 }
137  
138 # subroutine to check if TUI is valid
139 # input : $tui <- string containing a tui
140 # output: true | false <- integer indicating if the tui is valid
141 sub _validTui {
142  
143 0 ▶ my $self = shift;
Subroutine _validTui: not called CC=2 SCAR=17.9
144 0 my $st = shift;
145
146 0 ▶ if($st=~/T[0-9][0-9][0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st =~ /T[0-9][0-9][0-9]/) { } 0 0 0
147 0 return 1;
148 }
149 else {
150 0 return 0;
151 }
152 }
153  
154 # sets up the error handler module
155 # input : $parameters <- reference to a hash
156 # output: $self
157 sub new {
158  
159 72 ▶ my $self = {};
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
160 72 my $className = shift;
161
162 # Bless the object.
163 72 bless($self, $className);
164  
165 72 return $self;
166 }
167 58 1;
168 __END__
« blib/lib/UMLS/Interface.pm ↑ Summary utils/getCuiDef.pl »