lib/UMLS/Association/ErrorHandler.pm

filter: Statementstmt 40.2% 31 / 77 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 1 totaltotal 32.7% 37 / 113 SCAR 43.9
CC
14
Cov
30%
_error
156.0
_checkDbError
6.0
_validCui
6.0
CRAP 80.9
« lib/UMLS/Association/CUICollector.pm ↑ Summary script/umls-association.pl »
1 # UMLS::Association::ErrorHandler
2 #
3 # Perl module that provides a perl interface to the CUI network extracted
4 # from the MetaMapped Medline Baseline
5 #
6 # This program borrows heavily from the UMLS::Interface package.
7 #
8 # Copyright (c) 2015,
9 #
10 # Bridget T. McInnes, Virginia Commonwealth University
11 # btmcinnes at vcu.edu
12 #
13 # Keith Herbert, Virginia Commonwealth University
14 # herbertkb at vcu.edu
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to
28 #
29 # The Free Software Foundation, Inc.,
30 # 59 Temple Place - Suite 330,
31 # Boston, MA 02111-1307, USA.
32  
33 package UMLS::Association::ErrorHandler;
34  
35 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 # Errors and their error codes
42 1 my $e1 = "Database error (Error Code 1).";
43 1 my $e2 = "Self is undefined (Error Code 2).";
44 1 my $e3 = "A db is required (Error Code 3).";
45 1 my $e4 = "Undefined input value (Error Code 4).";
46 1 my $e5 = "NPP is zero or less error (Error Code 5).";
47 1 my $e6 = "Invalid CUI (Error Code 6).";
48 1 my $e7 = "UMLS::Association Database Content Error (Error Code 7).";
49 1 my $e8 = "UMLS::Association Package Error (Error Code 8).";
50 1 my $e9 = "Index Error (Error Code 9).";
51 1 my $e10 = "Option Error (Error Code 10).";
52 1 my $e11 = "Unsupported Option Error (Error Code 11).";
53  
54 # throws an error and exits the program
55 # input : $pkg <- package the error originated
56 # $function <- function the error originated
57 # $string <- error message
58 # $errorcode <- error code
59 # output:
60 sub _error {
61  
62 0 ▶ my $self = shift;
Subroutine _error: not called CC=12 SCAR=50.5
63 0 my $pkg = shift;
64 0 my $function = shift;
65 0 my $string = shift;
66 0 my $errorcode = shift;
67
68 0 my $errorstring = "";
69  
70 0 ▶ if($errorcode eq 1) { $errorstring = $e1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 1) 0 0 0
71 0 ▶ if($errorcode eq 2) { $errorstring = $e2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 2) 0 0 0
72 0 ▶ if($errorcode eq 3) { $errorstring = $e3; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 3) 0 0 0
73 0 ▶ if($errorcode eq 4) { $errorstring = $e4; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 4) 0 0 0
74 0 ▶ if($errorcode eq 5) { $errorstring = $e5; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 5) 0 0 0
75 0 ▶ if($errorcode eq 6) { $errorstring = $e6; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 6) 0 0 0
76 0 ▶ if($errorcode eq 7) { $errorstring = $e7; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 7) 0 0 0
77 0 ▶ if($errorcode eq 8) { $errorstring = $e8; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 8) 0 0 0
78 0 ▶ if($errorcode eq 9) { $errorstring = $e9; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 9) 0 0 0
79 0 ▶ if($errorcode eq 10) { $errorstring = $e10; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 10) 0 0 0
80 0 ▶ if($errorcode eq 11) { $errorstring = $e11; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 11) 0 0 0
81  
82 0 print STDERR "ERROR: $pkg->$function\n";
83 0 print STDERR "$errorstring\n";
84 0 print STDERR "$string\n";
85  
86 0 exit;
87 }
88  
89 # checks the database for an error
90 # input : $pkg => the Finder program
91 # $function => the function in the finder program
92 # $db => the database handler
93 # output:
94 sub _checkDbError {
95  
96 0 ▶ my $self = shift;
Subroutine _checkDbError: not called CC=2 SCAR=17.9
97 0 my $pkg = shift;
98 0 my $function = shift;
99 0 my $db = shift;
100  
101 0 my $errorcode = 1;
102
103 0 ▶ if($db->err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db->err) { } 0 0 0
104 0 my $errstring = "Error executing database query: $db->errstr()).";
105 0 $self->_error($pkg, $function, $errstring, $errorcode);
106 }
107 else {
108 0 return;
109 }
110 }
111  
112 # subroutine to check if CUI is valid
113 # input : $concept <- string containing a cui
114 # output: true | false <- integer indicating if the cui is valid
115 sub _validCui {
116  
117 0 ▶ my $self = shift;
Subroutine _validCui: not called CC=2 SCAR=17.9
118 0 my $concept = shift;
119
120 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
121 0 return 1;
122 }
123 else {
124 0 return 0;
125 }
126 }
127  
128 # sets up the error handler module
129 # input : $parameters <- reference to a hash
130 # output: $self
131 sub new {
132  
133 2 ▶ my $self = {};
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
134 2 my $className = shift;
135
136 # Bless the object.
137 2 bless($self, $className);
138  
139 2 return $self;
140 }
141 1 1;
142 __END__
« lib/UMLS/Association/CUICollector.pm ↑ Summary script/umls-association.pl »