EnsEMBL/DBLoader.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 50 CC 3 SCAR 19.5
CC
3
Cov
0%
_load_module
12.0
new
2.0
BEGIN
2.0
CRAP 7.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBLoader - Run time database loader
34  
35 =head1 SYNOPSIS
36  
37 $db =
38 Bio::EnsEMBL::DBLoader->new( "Bio::EnsEMBL::DBSQL::DBAdaptor/"
39 . "host=localhost;"
40 . "dbname=homo_sapiens_core_19_34a;"
41 . "user=ensro;" );
42  
43 # $db is a database object
44 $db = Bio::EnsEMBL::DBLoader->standard();
45  
46 # equivalent to
47 # Bio::EnsEMBL::DBLoader->new( $ENV{'ENSEMBL_DATABASE'} );
48  
49 =head1 DESCRIPTION
50  
51 This system provides a run-time loading of the database for ensembl,
52 allowing two things
53  
54 a) Only "using" the database module which is required for a
55 particular implementation
56  
57 b) Providing a simple string method to indicate where the database
58 is, allowing per sites defaults and other things as such
59  
60  
61 The string is parsed as follows:
62  
63 Before the / is the Perl database object to load, after are the
64 parameters to pass to that database. The parameters are series of
65 key=values separated by semi-colons. These are passed as a hash to the
66 new method of the database object
67  
68 =head1 METHODS
69  
70 =cut
71  
72 package Bio::EnsEMBL::DBLoader;
73 $Bio::EnsEMBL::DBLoader::VERSION = '114.0.0_50'; # TRIAL
74 $Bio::EnsEMBL::DBLoader::VERSION = '114.0.050';
75 use strict;
76  
77  
78 =head2 new
79  
80 Arg [1] : string $string
81 An Ensembl database locator string.
82 Example : Bio::EnsEMBL::DBSQL::DBLoader->new("Bio::EnsEMBL::DBSQL::DBAdaptor/host=localhost;dbname=homo_sapiens_core_19_34a;user=ensro;"
83 Description: Connects to an Ensembl database using the module specified in
84 the locator string.
85 Returntype : The module specified in the load string is returned.
86 Exceptions : thrown if the specified module cannot be instantiated or the
87 locator string cannot be parsed
88 Caller : ?
89 Status : Stable
90  
91 =cut
92  
93 sub new{
94 my ($class,$string) = @_;
95 my ($module,%hash);
96  
97 $string =~ /(\S+?)\/([\S+\s*]+)/ || die "Could not parse [$string] as a ensembl database locator. Needs database_module/params";
98 $module = $1;
99 my $param = $2;
100  
101 &_load_module($module);
102 my @param = split(/;/,$param);
103 foreach my $keyvalue ( @param ) {
104 $keyvalue =~ /(\S+?)=([\S*\s*]*)/ || do { warn("In loading $keyvalue, could not split into keyvalue for loading $module. Ignoring"); next; };
105  
106 my $key = $1;
107 my $value = $2;
108  
109 $hash{"-$key"} = $value;
110 }
111
112 my @kv = %hash;
113  
114 return "$module"->new(%hash);
115 }
116  
117  
118 sub _load_module{
119 my ($modulein) = @_;
120 my ($module,$load,$m);
121  
122 $module = "_<$modulein.pm";
123 $load = "$modulein.pm";
124 $load =~ s/::/\//g;
125
126 return 1 if $main::{$module};
127 eval {
128 require $load;
129 };
130 if( $@ ) {
131 print STDERR <<END;
132 $load: cannot be found
133 Exception $@
134  
135 END
136 ;
137 return;
138 }
139 return 1;
140 }
141  
142 1;