lib/MOSES/MOBY/Cache/Registries.pm

filter: Statementstmt 64.6% 75 / 116 Branchbran 33.8% 21 / 62 Conditioncond 28.3% 17 / 60 MC/DCmcdc 3.5% 1 / 28 Subroutinesub 94.7% 18 / 19 Podpod 75.0% 6 / 8 totaltotal 47.1% 138 / 293 CC 55 SCAR 41.0
CC
55
Cov
47%
_update_user_registries
173.2
add
52.4
remove
46.8
CRAP 60.2
« lib/MOSES/MOBY/Generators/GenTypes.pm ↑ Summary lib/MOSES/MOBY/Base.pm »
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Cache::Registries
3 # Author: Martin Senger <martin.senger@gmail.com>
4 # For copyright and disclaimer see below.
5 #
6 # $Id: Registries.pm,v 1.6 2009/08/19 17:07:26 kawas Exp $
7 #-----------------------------------------------------------------
8  
9 package MOSES::MOBY::Cache::Registries;
10 2 ▶use MOSES::MOBY::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use base qw ( MOSES::MOBY::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # add versioning to this module
15 2 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 $VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;
17  
18 2 ▶use vars qw/ %REGISTRIES /;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 our (%REGISTRIES);
22 2 my $already_init = 0;
23  
24 4 ▶ sub is_init {
Subroutine is_init: called CC=1 SCAR=0.0
Pod undocumented
25 4 return $already_init++;
26 }
27  
28 2 ▶ sub init_reg {
Subroutine init_reg: called CC=5 SCAR=17.4
Pod undocumented
29 #-----------------------------------------------------------------
30 # A hard-coded list of the known registries.
31 #
32 # Please fill all details if you are adding new registry here.
33 #
34 # Do not create synonyms starting with 'http://' (they are in the
35 # roles of the hash keys) - this is how some methods distinguish
36 # between synonym and endpoint.
37 #
38 #-----------------------------------------------------------------
39 2 %REGISTRIES = (
40 iCAPTURE => {
41 endpoint => 'http://moby.ucalgary.ca/moby/MOBY-Central.pl',
42 namespace => 'http://moby.ucalgary.ca/MOBY/Central',
43 name => 'Sun Centre of Excellence, Calgary',
44 contact => 'Edward Kawas (edward.kawas@gmail.com)',
45 public => 'yes',
46 text => 'A curated public registry hosted at U of C, Calgary',
47 },
48 IRRI => {
49 endpoint => 'http://cropwiki.irri.org/cgi-bin/MOBY-Central.pl',
50 namespace => 'http://cropwiki.irri.org/MOBY/Central',
51 name => 'IRRI, Philippines',
52 contact => 'Mylah Rystie Anacleto (m.anacleto@cgiar.org)',
53 public => 'yes',
54 text => 'The MOBY registry at the International Rice Research Institute (IRRI) is intended mostly for Generation Challenge Program (GCP) developers. It allows the registration of experimental moby entities within GCP.',
55 },
56 testing => {
57 endpoint => 'http://mobytest.biordf.net/MOBY-Central.pl',
58 namespace => 'http://mobytest.biordf.net/MOBY/Central',
59 name => 'Testing BioMoby registry',
60 contact => 'Edward Kawas (edward.kawas+testregistry@gmail.com)',
61 public => 'yes',
62 },
63 );
64  
65 # create a default registry
66 2 $REGISTRIES{default} = $REGISTRIES{iCAPTURE};
67  
68 # read from config file user registries
69 # add user_registries
70 2 eval {
71 2 do {
72  
73 # is this the best way?
74 2 ▶ use lib $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || '/make/believe'
l!l
02
MC/DC0%0/1
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || '/make/believe'
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
Truth table50%1/2
A
A= $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
Aresult
11
00
75 2 || "/make/believe";
76 2 ▶ use vars qw( %USER_REGISTRIES );
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 ▶ require $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
Branch: 1 branch
BranchTrueFalseTotal
if defined $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME 0 2 2
78 if defined $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME;
79 2 foreach my $key ( sort keys %USER_REGISTRIES ) {
80  
81 # script if key exists
82 0 ▶ next if exists $REGISTRIES{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $MOSES::MOBY::Cache::Registries::REGISTRIES{$key} 0 0 0
83 0 $REGISTRIES{$key} = $USER_REGISTRIES{$key};
84 }
85 }
86 };
87 2 ▶ unshift @INC, "/make/believe" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
88 }
89 }
90  
91 #-----------------------------------------------------------------
92 # init
93 #-----------------------------------------------------------------
94 4 ▶sub init {
Subroutine init: called CC=2 SCAR=6.9
Pod documented
95 4 my $self = shift;
96 4 ▶ init_reg() unless is_init();
Branch: 1 branch
BranchTrueFalseTotal
unless is_init() 2 2 4
97 4 my %cloned = %REGISTRIES;
98 4 $self->{registries} = \%cloned;
99 }
100  
101 #-----------------------------------------------------------------
102 # list
103 #-----------------------------------------------------------------
104 1 ▶sub list {
Subroutine list: called CC=2 SCAR=7.6
Pod documented
105 1 my $self = shift;
106 1 ▶ return sort keys %{ $self->{registries} } if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 1 0 1
107  
108 # do this so that we can get user defined registries
109 0 return MOSES::MOBY::Cache::Registries->new()->list();
110 }
111  
112 #-----------------------------------------------------------------
113 # get
114 #-----------------------------------------------------------------
115 11 ▶sub get {
Subroutine get: called CC=3 SCAR=11.4
Pod documented
116 11 my ( $self, $abbrev ) = @_;
117 11 ▶ $abbrev ||= 'default';
Condition100%2/2
$abbrev ||= "default"
l!l
101
MC/DC100%1/1
$abbrev ||= "default"
$abbrev
Truth table100%2/2
A
A= $abbrev
Aresult
11
00
118 11 ▶ return $self->{registries}->{$abbrev} if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 11 0 11
119  
120 # do this so that we can get user defined registries
121 0 return MOSES::MOBY::Cache::Registries->new()->get($abbrev);
122 }
123  
124 #-----------------------------------------------------------------
125 # all
126 #-----------------------------------------------------------------
127 0 ▶sub all {
Subroutine all: not called CC=2 SCAR=17.9
Pod documented
128 0 my $self = shift;
129 0 ▶ return $self->{registries} if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 0 0 0
130  
131 # do this so that we can get user defined registries
132 0 return MOSES::MOBY::Cache::Registries->new()->all;
133 }
134  
135 #-----------------------------------------------------------------
136 # add
137 #-----------------------------------------------------------------
138 1 ▶sub add {
Subroutine add: called CC=18 SCAR=39.6
Pod documented
139 1 my ( $self, %reg ) = @_;
140  
141 # add using object methods ...
142 1 ▶ return MOSES::MOBY::Cache::Registries->new()->add(%reg) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
143  
144 # check for force
145 1 my $force = exists $reg{force};
146  
147 # check %reg hash for conformance and existance
148 return -1
149 unless defined $reg{namespace}
150 and defined $reg{endpoint}
151 and defined $reg{synonym}
152 and defined $reg{text}
153 and defined $reg{name}
154 and defined $reg{contact}
155 1 ▶ and defined $reg{public};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"} and defined $reg{"name"} and defined $reg{"contact"} and defined $reg{"public"} 0 1 1
Condition33%6/18
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"} and defined $reg{"name"} and defined $reg{"contact"} and defined $reg{"public"}
!ll&&!rl&&r
001
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"} and defined $reg{"name"} and defined $reg{"contact"}
!ll&&!rl&&r
001
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"} and defined $reg{"name"}
!ll&&!rl&&r
001
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"}
!ll&&!rl&&r
001
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"}
!ll&&!rl&&r
001
defined $reg{"namespace"} and defined $reg{"endpoint"}
!ll&&!rl&&r
001
MC/DC0%0/7
defined $reg{"namespace"} and defined $reg{"endpoint"} and defined $reg{"synonym"} and defined $reg{"text"} and defined $reg{"name"} and defined $reg{"contact"} and defined $reg{"public"}
defined $reg{"namespace"} defined $reg{"endpoint"} defined $reg{"synonym"} defined $reg{"text"} defined $reg{"name"} defined $reg{"contact"} defined $reg{"public"}
Truth table12%1/8
A and B and C and D and E and F and G
A= defined $reg{"namespace"}B= defined $reg{"endpoint"}C= defined $reg{"synonym"}D= defined $reg{"text"}E= defined $reg{"name"}F= defined $reg{"contact"}G= defined $reg{"public"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
156  
157 $reg{public} = 'yes'
158 1 ▶ unless $reg{public} eq 'yes' || $reg{public} eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
unless $reg{"public"} eq "yes" or $reg{"public"} eq "no" 0 1 1
Condition33%1/3
$reg{"public"} eq "yes" or $reg{"public"} eq "no"
l!l&&r!l&&!r
010
MC/DC0%0/2
$reg{"public"} eq "yes" or $reg{"public"} eq "no"
$reg{"public"} eq "yes" $reg{"public"} eq "no"
Truth table33%1/3
A or B
A= $reg{"public"} eq "yes"B= $reg{"public"} eq "no"
ABresult
1X1
011
000
159  
160 return -1
161 1 ▶ if $reg{synonym} =~ m"^http://";
Branch: 1 branch
BranchTrueFalseTotal
if $reg{"synonym"} =~ m[^http://] 0 1 1
162  
163 return -2
164 unless ( ( not defined $self->{registries}->{ $reg{synonym} } )
165 1 ▶ or $force );
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $self->{"registries"}{$reg{"synonym"}} or $force 0 1 1
Condition33%1/3
not defined $self->{"registries"}{$reg{"synonym"}} or $force
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $self->{"registries"}{$reg{"synonym"}} or $force
not defined $self->{"registries"}{$reg{"synonym"}} $force
Truth table33%1/3
not(A) or B
A= not defined $self->{"registries"}{$reg{"synonym"}}B= $force
ABresult
1X1
011
000
166  
167 # call update ...
168 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) 1 0 1
169 1 eval { $self->_update_user_registries(%reg); };
170 1 ▶ $LOG->warn("Error updating user registries: $@")
Branch: 1 branch
BranchTrueFalseTotal
if $MOSES::MOBY::Cache::Registries::LOG->is_warn and $@ 0 1 1
Condition33%1/3
$MOSES::MOBY::Cache::Registries::LOG->is_warn and $@
!ll&&!rl&&r
100
MC/DC0%0/2
$MOSES::MOBY::Cache::Registries::LOG->is_warn and $@
$MOSES::MOBY::Cache::Registries::LOG->is_warn $@
Truth table33%1/3
A and B
A= $MOSES::MOBY::Cache::Registries::LOG->is_warnB= $@
ABresult
0X0
100
111
171 if ( $LOG->is_warn )
172 and $@;
173  
174 # return 0 if $@; # removed because we should be able to
175  
176 #update $self->{registries}
177 $self->{registries}->{ $reg{synonym} } = {
178 endpoint => $reg{endpoint},
179 namespace => $reg{namespace},
180 name => $reg{name},
181 contact => $reg{contact},
182 public => $reg{public},
183 text => $reg{text},
184 1 };
185  
186 # return success
187 1 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
188 0 return 1;
189 } if ref $self;
190 }
191  
192 #-----------------------------------------------------------------
193 # remove
194 #-----------------------------------------------------------------
195 1 ▶sub remove {
Subroutine remove: called CC=13 SCAR=38.5
Pod documented
196 1 my ( $self, $name ) = @_;
197  
198 # add using object methods ...
199 1 ▶ return MOSES::MOBY::Cache::Registries->new()->remove($name)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
200 unless ref $self;
201 1 ▶ return 1 unless defined $self->{registries}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"registries"}{$name} 0 1 1
202  
203 # do the remove
204 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) 1 0 1
205 1 eval {
206  
207 # remove from file
208 1 ▶ my %args = ( # some default values
Condition50%2/4
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || ''
l!l
01
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME || 'USER_REGISTRIES'
l!l
01
MC/DC0%0/1
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || ''
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
MC/DC0%0/1
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME || 'USER_REGISTRIES'
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
Truth table50%1/2
A
A= $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
Aresult
11
00
Truth table50%1/2
A
A= $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
Aresult
11
00
209 user_reg_dir =>
210 ( $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || '' ),
211 user_reg_table => (
212 $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
213 || 'USER_REGISTRIES'
214 ),
215 );
216 die
217 "Couldn't find the location to 'USER_REGISTRIES' in the configuration file!"
218 1 ▶ if $args{user_reg_dir} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"user_reg_dir"} eq "" 1 0 1
219  
220 # read the current user registry table
221 unshift( @INC, $args{user_reg_dir} )
222 0 ; # place where USER_REGISTRIES could be
223 2 ▶ use vars qw ( %USER_REGISTRIES );
Subroutine BEGIN: called CC=1 SCAR=0.0
224 0 eval { require $args{user_reg_table} };
225 0 my $file_with_table;
226 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
227 $LOG->warn( "Cannot find table of USER_REGISTRIES '"
228 . $args{user_reg_table}
229 0 . "': $@" );
230 $file_with_table = File::Spec->catfile( $args{user_reg_dir},
231 0 $args{user_reg_table} );
232 } else {
233 0 $file_with_table = $INC{ $args{user_reg_table} };
234 }
235  
236 # remove from user regs table
237 0 delete $USER_REGISTRIES{$name};
238  
239 # ...and write it back to a disk
240 0 require Data::Dumper;
241 0 ▶ open DISPATCH, ">$file_with_table"
Branch: 1 branch
BranchTrueFalseTotal
open DISPATCH, ">$file_with_table" or $self->throw("Cannot open for writing '${file_with_table}': $!\n") 0 0 0
242 or
243 $self->throw("Cannot open for writing '$file_with_table': $!\n");
244 0 ▶ print DISPATCH Data::Dumper->Dump( [ \%USER_REGISTRIES ],
Branch: 1 branch
BranchTrueFalseTotal
print DISPATCH "Data::Dumper"->Dump([\%MOSES::MOBY::Cache::Registries::USER_REGISTRIES], ["*USER_REGISTRIES"]) or $self->throw("cannot write to '${file_with_table}': $!\n") 0 0 0
245 ['*USER_REGISTRIES'] )
246 or $self->throw("cannot write to '$file_with_table': $!\n");
247 0 close DISPATCH;
248 0 $LOG->info(
249 "\nUpdated user reg table '$file_with_table'. New contents:\n"
250 . $self->toString( \%USER_REGISTRIES ) );
251 };
252 1 ▶ $LOG->warn("Error removing user registries: $@")
Branch: 1 branch
BranchTrueFalseTotal
if $MOSES::MOBY::Cache::Registries::LOG->is_warn and $@ 0 1 1
Condition33%1/3
$MOSES::MOBY::Cache::Registries::LOG->is_warn and $@
!ll&&!rl&&r
100
MC/DC0%0/2
$MOSES::MOBY::Cache::Registries::LOG->is_warn and $@
$MOSES::MOBY::Cache::Registries::LOG->is_warn $@
Truth table33%1/3
A and B
A= $MOSES::MOBY::Cache::Registries::LOG->is_warnB= $@
ABresult
0X0
100
111
253 if ( $LOG->is_warn )
254 and $@;
255  
256 #update $self->{registries}
257 1 delete $self->{registries}->{$name};
258  
259 # could remove from persistent store
260 1 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
261  
262 # return success
263 0 return 1;
264 } if ref $self;
265 }
266  
267 #-----------------------------------------------------------------
268 # _update_user_registries
269 #-----------------------------------------------------------------
270  
271 1 ▶sub _update_user_registries {
Subroutine _update_user_registries: called CC=16 SCAR=51.5
272 1 my ( $self, @args ) = @_;
273 1 ▶ my %args = ( # some default values
Condition50%2/4
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || ''
l!l
01
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME || 'USER_REGISTRIES'
l!l
01
MC/DC0%0/1
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || ''
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
MC/DC0%0/1
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME || 'USER_REGISTRIES'
$MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
Truth table50%1/2
A
A= $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR
Aresult
11
00
Truth table50%1/2
A
A= $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
Aresult
11
00
274 user_reg_dir => ( $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_DIR || '' ),
275 user_reg_table => (
276 $MOBYCFG::USER_REGISTRIES_USER_REGISTRIES_FILENAME
277 || 'USER_REGISTRIES'
278 ),
279  
280 # and the real parameters
281 @args
282 );
283 die
284 "Couldn't find the location to 'USER_REGISTRIES' in the configuration file!"
285 1 ▶ if $args{user_reg_dir} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"user_reg_dir"} eq "" 1 0 1
286  
287 # check %args for the right parameters, endpoint, namespace, name, synonym, contact, text, public
288 die "Arguments to update user registries are incomplete."
289 unless defined $args{namespace}
290 and defined $args{endpoint}
291 and defined $args{synonym}
292 and defined $args{text}
293 and defined $args{name}
294 and defined $args{contact}
295 0 ▶ and defined $args{public};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"} and defined $args{"name"} and defined $args{"contact"} and defined $args{"public"} 0 0 0
Condition0%0/18
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"} and defined $args{"name"} and defined $args{"contact"} and defined $args{"public"}
!ll&&!rl&&r
000
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"} and defined $args{"name"} and defined $args{"contact"}
!ll&&!rl&&r
000
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"} and defined $args{"name"}
!ll&&!rl&&r
000
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"}
!ll&&!rl&&r
000
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"}
!ll&&!rl&&r
000
defined $args{"namespace"} and defined $args{"endpoint"}
!ll&&!rl&&r
000
MC/DC0%0/7
defined $args{"namespace"} and defined $args{"endpoint"} and defined $args{"synonym"} and defined $args{"text"} and defined $args{"name"} and defined $args{"contact"} and defined $args{"public"}
defined $args{"namespace"} defined $args{"endpoint"} defined $args{"synonym"} defined $args{"text"} defined $args{"name"} defined $args{"contact"} defined $args{"public"}
Truth table0%0/8
A and B and C and D and E and F and G
A= defined $args{"namespace"}B= defined $args{"endpoint"}C= defined $args{"synonym"}D= defined $args{"text"}E= defined $args{"name"}F= defined $args{"contact"}G= defined $args{"public"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
296  
297 die "Registry synonyms should not start with http ..."
298 0 ▶ if $args{synonym} =~ m"^http://";
Branch: 1 branch
BranchTrueFalseTotal
if $args{"synonym"} =~ m[^http://] 0 0 0
299  
300 0 my $outdir = File::Spec->rel2abs( $args{user_reg_dir} );
301 0 ▶ $LOG->debug( "Arguments for generating user registries table: "
Branch: 1 branch
BranchTrueFalseTotal
if $MOSES::MOBY::Cache::Registries::LOG->is_debug 0 0 0
302 . $self->toString( \%args ) )
303 if ( $LOG->is_debug );
304  
305 # read the current user registry table
306 0 unshift( @INC, $args{user_reg_dir} ); # place where USER_REGISTRIES could be
307 2 ▶ use vars qw ( %USER_REGISTRIES );
Subroutine BEGIN: called CC=1 SCAR=0.0
308 0 eval { require $args{user_reg_table} };
309 0 my $file_with_table;
310 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
311 $LOG->warn( "Cannot find table of USER_REGISTRIES '"
312 . $args{user_reg_table}
313 0 . "': $@" );
314 $file_with_table =
315 0 File::Spec->catfile( $args{user_reg_dir}, $args{user_reg_table} );
316 } else {
317 0 $file_with_table = $INC{ $args{user_reg_table} };
318 }
319  
320 # update user regs table
321 $USER_REGISTRIES{ $args{synonym} } = {
322 endpoint => $args{endpoint},
323 namespace => $args{namespace},
324 name => $args{name},
325 contact => $args{contact},
326 public => $args{public},
327 text => $args{text},
328 0 };
329  
330 # ...and write it back to a disk
331 0 require Data::Dumper;
332 0 ▶ open DISPATCH, ">$file_with_table"
Branch: 1 branch
BranchTrueFalseTotal
open DISPATCH, ">$file_with_table" or $self->throw("Cannot open for writing '${file_with_table}': $!\n") 0 0 0
333 or $self->throw("Cannot open for writing '$file_with_table': $!\n");
334 0 ▶ print DISPATCH Data::Dumper->Dump( [ \%USER_REGISTRIES ],
Branch: 1 branch
BranchTrueFalseTotal
print DISPATCH "Data::Dumper"->Dump([\%MOSES::MOBY::Cache::Registries::USER_REGISTRIES], ["*USER_REGISTRIES"]) or $self->throw("cannot write to '${file_with_table}': $!\n") 0 0 0
335 ['*USER_REGISTRIES'] )
336 or $self->throw("cannot write to '$file_with_table': $!\n");
337 0 close DISPATCH;
338 0 $LOG->info( "\nUpdated user reg table '$file_with_table'. New contents:\n"
339 . $self->toString( \%USER_REGISTRIES ) );
340 }
341  
342 2 1;
343 __END__
« lib/MOSES/MOBY/Generators/GenTypes.pm ↑ Summary lib/MOSES/MOBY/Base.pm »