Bio/Root/Storable.pm

filter: Statementstmt 83.7% 149 / 178 Branchbran 56.7% 42 / 74 Conditioncond 45.0% 9 / 20 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 100% 23 / 23 Podpod 100% 13 / 13 totaltotal 74.1% 238 / 321 CC 48 SCAR 29.4
CC
48
Cov
74%
serialise
60.7
retrieve
26.3
statefile
6.1
CRAP 18.9
« Bio/SearchIO/Writer/HSPTableWriter.pm ↑ Summary Bio/SearchIO/exonerate.pm »
1 package Bio::Root::Storable;
2 2 $Bio::Root::Storable::VERSION = '1.7.8';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Bio::Root::Storable - Safely store/retrieve objects from disk
12  
13 =head1 SYNOPSIS
14  
15 my $storable = Bio::Root::Storable->new();
16  
17 # Store/retrieve using class retriever
18 my $token = $storable->store();
19 my $storable2 = Bio::Root::Storable->retrieve( $token );
20  
21 # Store/retrieve using object retriever
22 my $storable2 = $storable->new_retrievable();
23 $storable2->retrieve();
24  
25 =head1 DESCRIPTION
26  
27 Generic module that allows objects to be safely stored/retrieved from
28 disk. Can be inhereted by any BioPerl object. As it will not usually
29 be the first class in the inheretence list, _initialise_storable()
30 should be called during object instantiation.
31  
32 Object storage is recursive; If the object being stored contains other
33 storable objects, these will be stored separately, and replaced by a
34 skeleton object in the parent hierarchy. When the parent is later
35 retrieved, its children remain in the skeleton state until explicitly
36 retrieved by the parent. This lazy-retrieve approach has obvious
37 memory efficiency benefits for certain applications.
38  
39  
40 By default, objects are stored in binary format (using the Perl
41 Storable module). Earlier versions of Perl5 do not include Storable as
42 a core module. If this is the case, ASCII object storage (using the
43 Perl Data::Dumper module) is used instead.
44  
45 ASCII storage can be enabled by default by setting the value of
46 $Bio::Root::Storable::BINARY to false.
47  
48 =head1 AUTHOR Will Spooner
49  
50 =cut
51  
52 2 ▶use vars qw( $BINARY );
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 2 ▶BEGIN{
Subroutine BEGIN: called CC=2 SCAR=7.1
55 2 ▶ if( eval "require Storable" ){
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require Storable") 2 0 2
56 2 Storable->import( 'freeze', 'thaw' );
57 2 $BINARY = 1;
58 }
59 }
60  
61 #----------------------------------------------------------------------
62  
63 =head2 new
64  
65 Arg [1] : -workdir => filesystem path,
66 -template => tmpfile template,
67 -suffix => tmpfile suffix,
68 Function : Builds a new Bio::Root::Storable inhereting object
69 Returntype: Bio::Root::Storable inhereting object
70 Exceptions:
71 Caller :
72 Example : $storable = Bio::Root::Storable->new()
73  
74 =cut
75  
76 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77 4 my ($caller, @args) = @_;
78 4 my $self = $caller->SUPER::new(@args);
79 4 $self->_initialise_storable;
80 4 return $self;
81 }
82  
83 #----------------------------------------------------------------------
84  
85 =head2 _initialise_storable
86  
87 Arg [1] : See 'new' method
88 Function : Initialises storable-specific attributes
89 Returntype: boolean
90 Exceptions:
91 Caller :
92 Example :
93  
94 =cut
95  
96 8 ▶sub _initialise_storable {
Subroutine _initialise_storable: called CC=4 SCAR=13.9
97 8 my $self = shift;
98 8 my( $workdir, $template, $suffix ) =
99 $self->_rearrange([qw(WORKDIR TEMPLATE SUFFIX)], @_ );
100 8 ▶ $workdir && $self->workdir ( $workdir );
Branch: 1 branch
BranchTrueFalseTotal
$workdir and $self->workdir($workdir) 2 6 8
101 8 ▶ $template && $self->template( $template );
Branch: 1 branch
BranchTrueFalseTotal
$template and $self->template($template) 2 6 8
102 8 ▶ $suffix && $self->suffix ( $suffix );
Branch: 1 branch
BranchTrueFalseTotal
$suffix and $self->suffix($suffix) 0 8 8
103 8 return 1;
104 }
105  
106  
107  
108 #----------------------------------------------------------------------
109  
110 =head2 statefile
111  
112 Arg [1] : string (optional)
113 Function : Accessor for the file to write state into.
114 Should not normally use as a setter - let Root::IO
115 do this for you.
116 Returntype: string
117 Exceptions:
118 Caller : Bio::Root::Storable->store
119 Example : my $statefile = $obj->statefile();
120  
121 =cut
122  
123 28 ▶sub statefile{
Subroutine statefile: called CC=6 SCAR=18.1
Pod documented
124 28 my $key = '_statefile';
125 28 my $self = shift;
126  
127 0 ▶ if( @_ ){ $self->{$key} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 28 28
128  
129 28 ▶ if( ! $self->{$key} ){ # Create a new statefile
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$key}) 4 24 28
130 4 my $workdir = $self->workdir;
131 4 my $template = $self->template;
132 4 my $suffix = $self->suffix;
133  
134 # TODO: add cleanup and unlink methods. For now, we'll keep the
135 # statefile hanging around.
136 4 my @args = ( CLEANUP=>0, UNLINK=>0 );
137 4 ▶ if( $template ){ push( @args, 'TEMPLATE' => $template )};
Branch: 1 branch
BranchTrueFalseTotal
if ($template) 4 0 4
138 4 ▶ if( $workdir ){ push( @args, 'DIR' => $workdir )};
Branch: 1 branch
BranchTrueFalseTotal
if ($workdir) 4 0 4
139 4 ▶ if( $suffix ){ push( @args, 'SUFFIX' => $suffix )};
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) 2 2 4
140 4 my( $fh, $file ) = Bio::Root::IO->new->tempfile( @args );
141 # If filehandle is not stored, don't leave it open
142 4 $fh->close;
143  
144 4 $self->{$key} = $file;
145 }
146  
147 28 return $self->{$key};
148 }
149  
150 #----------------------------------------------------------------------
151  
152 =head2 workdir
153  
154 Arg [1] : string (optional) (TODO - convert to array for x-platform)
155 Function : Accessor for the statefile directory. Defaults to File::Spec->tmpdir
156 Returntype: string
157 Exceptions:
158 Caller :
159 Example : $obj->workdir('/tmp/foo');
160  
161 =cut
162  
163 22 ▶sub workdir {
Subroutine workdir: called CC=4 SCAR=14.0
Pod documented
164 22 my $key = '_workdir';
165 22 my $self = shift;
166 22 ▶ if( @_ ){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 20 22
167 2 my $caller = join( ', ', (caller(0))[1..2] );
168 2 ▶ $self->{$key} && $self->debug("Overwriting workdir: probably bad!");
Branch: 1 branch
BranchTrueFalseTotal
$self->{$key} and $self->debug("Overwriting workdir: probably bad!") 2 0 2
169 2 $self->{$key} = shift
170 }
171 #$self->{$key} ||= $Bio::Root::IO::TEMPDIR;
172 22 ▶ $self->{$key} ||= File::Spec->tmpdir();
Condition66%2/3
$self->{$key} ||= "File::Spec"->tmpdir
l!l&&r!l&&!r
1840
MC/DC0%0/2
$self->{$key} ||= "File::Spec"->tmpdir
$self->{$key} "File::Spec"->tmpdir
Truth table66%2/3
A ||= B
A= $self->{$key}B= "File::Spec"->tmpdir
ABresult
1X1
011
000
173 22 return $self->{$key};
174 }
175  
176 #----------------------------------------------------------------------
177  
178 =head2 template
179  
180 Arg [1] : string (optional)
181 Function : Accessor for the statefile template. Defaults to XXXXXXXX
182 Returntype: string
183 Exceptions:
184 Caller :
185 Example : $obj->workdir('RES_XXXXXXXX');
186  
187 =cut
188  
189 24 ▶sub template {
Subroutine template: called CC=3 SCAR=11.0
Pod documented
190 24 my $key = '_template';
191 24 my $self = shift;
192 24 ▶ if( @_ ){ $self->{$key} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 20 24
193 24 ▶ $self->{$key} ||= 'XXXXXXXX';
Condition100%2/2
$self->{$key} ||= "XXXXXXXX"
l!l
222
MC/DC100%1/1
$self->{$key} ||= "XXXXXXXX"
$self->{$key}
Truth table100%2/2
A
A= $self->{$key}
Aresult
11
00
194 24 return $self->{$key};
195 }
196  
197 #----------------------------------------------------------------------
198  
199 =head2 suffix
200  
201 Arg [1] : string (optional)
202 Function : Accessor for the statefile template.
203 Returntype: string
204 Exceptions:
205 Caller :
206 Example : $obj->suffix('.state');
207  
208 =cut
209  
210 22 ▶sub suffix {
Subroutine suffix: called CC=2 SCAR=6.9
Pod documented
211 22 my $key = '_suffix';
212 22 my $self = shift;
213 22 ▶ if( @_ ){ $self->{$key} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 20 22
214 22 return $self->{$key};
215 }
216  
217 #----------------------------------------------------------------------
218  
219 =head2 new_retrievable
220  
221 Arg [1] : Same as for 'new'
222 Function : Similar to store, except returns a 'skeleton' of the calling
223 object, rather than the statefile.
224 The skeleton can be repopulated by calling 'retrieve'. This
225 will be a clone of the original object.
226 Returntype: Bio::Root::Storable inhereting object
227 Exceptions:
228 Caller :
229 Example : my $skel = $obj->new_retrievable(); # skeleton
230 $skel->retrieve(); # clone
231  
232 =cut
233  
234 4 ▶sub new_retrievable{
Subroutine new_retrievable: called CC=2 SCAR=7.2
Pod documented
235 4 my $self = shift;
236 4 my @args = @_;
237  
238 4 $self->_initialise_storable( @args );
239  
240 0 ▶ if( $self->retrievable ){ return $self->clone } # Clone retrievable
Branch: 1 branch
BranchTrueFalseTotal
if ($self->retrievable) 0 4 4
241 4 return bless( { _statefile => $self->store(@args),
242 _workdir => $self->workdir,
243 _suffix => $self->suffix,
244 _template => $self->template,
245 _retrievable => 1 },
246 ref( $self ) );
247 }
248  
249 #----------------------------------------------------------------------
250  
251 =head2 retrievable
252  
253 Arg [1] : none
254 Function : Reports whether the object is in 'skeleton' state, and the
255 'retrieve' method can be called.
256 Returntype: boolean
257 Exceptions:
258 Caller :
259 Example : if( $obj->retrievable ){ $obj->retrieve }
260  
261 =cut
262  
263 30 ▶sub retrievable {
Subroutine retrievable: called CC=2 SCAR=6.9
Pod documented
264 30 my $self = shift;
265 30 ▶ if( @_ ){ $self->{_retrievable} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 12 30
266 30 return $self->{_retrievable};
267 }
268  
269 #----------------------------------------------------------------------
270  
271 =head2 token
272  
273 Arg [1] : None
274 Function : Accessor for token attribute
275 Returntype: string. Whatever retrieve needs to retrieve.
276 This base implementation returns the statefile
277 Exceptions:
278 Caller :
279 Example : my $token = $obj->token();
280  
281 =cut
282  
283 2 ▶sub token{
Subroutine token: called CC=1 SCAR=0.0
Pod documented
284 2 my $self = shift;
285 2 return $self->statefile;
286 }
287  
288  
289 #----------------------------------------------------------------------
290  
291 =head2 store
292  
293 Arg [1] : none
294 Function : Saves a serialised representation of the object structure
295 to disk. Returns the name of the file that the object was
296 saved to.
297 Returntype: string
298  
299 Exceptions:
300 Caller :
301 Example : my $token = $obj->store();
302  
303 =cut
304  
305 10 ▶sub store{
Subroutine store: called CC=1 SCAR=0.0
Pod documented
306 10 my $self = shift;
307 10 my $statefile = $self->statefile;
308 10 my $store_obj = $self->serialise;
309 10 my $io = Bio::Root::IO->new( ">$statefile" );
310 10 $io->_print( $store_obj );
311 10 $self->debug( "STORING $self to $statefile\n" );
312 # If filehandle is not stored, don't leave it open
313 10 $io->close;
314 10 return $statefile;
315 }
316  
317 #----------------------------------------------------------------------
318  
319 =head2 serialise
320  
321 Arg [1] : none
322 Function : Prepares the the serialised representation of the object.
323 Object attribute names starting with '__' are skipped.
324 This is useful for those that do not serialise too well
325 (e.g. filehandles).
326 Attributes are examined for other storable objects. If these
327 are found they are serialised separately using 'new_retrievable'
328 Returntype: string
329 Exceptions:
330 Caller :
331 Example : my $serialised = $obj->serialise();
332  
333 =cut
334  
335 12 ▶sub serialise{
Subroutine serialise: called CC=14 SCAR=41.1
Pod documented
336 12 my $self = shift;
337  
338 # Create a new object of same class that is going to be serialised
339 12 my $store_obj = bless( {}, ref( $self ) );
340  
341 12 my %retargs = ( -workdir =>$self->workdir,
342 -suffix =>$self->suffix,
343 -template=>$self->template );
344 # Assume that other storable bio objects held by this object are
345 # only 1-deep.
346  
347 12 foreach my $key( keys( %$self ) ){
348 62 ▶ if( $key =~ /^__/ ){ next } # Ignore keys starting with '__'
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^__/) 8 54 62
349 54 my $value = $self->{$key};
350  
351 # Scalar value
352 54 ▶ if( ! ref( $value ) ){
Branch: 4 branches
BranchTrueFalseTotal
if (not ref $value) { } 52 2 54
elsif (ref($value) =~ /^Bio::/ and $value->isa('Bio::Root::Storable')) { } 2 0 2
elsif (ref $value eq 'ARRAY') { } 0 0 0
elsif (ref $value eq 'HASH') { } 0 0 0
353 52 $store_obj->{$key} = $value;
354 }
355  
356 # Bio::Root::Storable obj: save placeholder
357 ▶ elsif( ref($value) =~ /^Bio::/ and $value->isa('Bio::Root::Storable') ){
Condition33%1/3
ref($value) =~ /^Bio::/ and $value->isa("Bio::Root::Storable")
!ll&&!rl&&r
002
MC/DC0%0/2
ref($value) =~ /^Bio::/ and $value->isa("Bio::Root::Storable")
ref($value) =~ /^Bio::/ $value->isa("Bio::Root::Storable")
Truth table33%1/3
A and B
A= ref($value) =~ /^Bio::/B= $value->isa("Bio::Root::Storable")
ABresult
0X0
100
111
358 # Bio::Root::Storable
359 2 $store_obj->{$key} = $value->new_retrievable( %retargs );
360 2 next;
361 }
362  
363 # Arrayref value. Look for Bio::Root::Storable objs
364 elsif( ref( $value ) eq 'ARRAY' ){
365 0 my @ary;
366 0 foreach my $val( @$value ){
367 0 ▶ if( ref($val) =~ /^Bio::/ and $val->isa('Bio::Root::Storable') ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /^Bio::/ and $val->isa('Bio::Root::Storable')) { } 0 0 0
Condition0%0/3
ref($val) =~ /^Bio::/ and $val->isa("Bio::Root::Storable")
!ll&&!rl&&r
000
MC/DC0%0/2
ref($val) =~ /^Bio::/ and $val->isa("Bio::Root::Storable")
ref($val) =~ /^Bio::/ $val->isa("Bio::Root::Storable")
Truth table0%0/3
A and B
A= ref($val) =~ /^Bio::/B= $val->isa("Bio::Root::Storable")
ABresult
0X0
100
111
368 0 push( @ary, $val->new_retrievable( %retargs ) );
369 }
370 0 else{ push( @ary, $val ) }
371 }
372 0 $store_obj->{$key} = \@ary;
373 }
374  
375 # Hashref value. Look for Bio::Root::Storable objs
376 elsif( ref( $value ) eq 'HASH' ){
377 0 my %hash;
378 0 foreach my $k2( keys %$value ){
379 0 my $val = $value->{$k2};
380 0 ▶ if( ref($val) =~ /^Bio::/ and $val->isa('Bio::Root::Storable') ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /^Bio::/ and $val->isa('Bio::Root::Storable')) { } 0 0 0
Condition0%0/3
ref($val) =~ /^Bio::/ and $val->isa("Bio::Root::Storable")
!ll&&!rl&&r
000
MC/DC0%0/2
ref($val) =~ /^Bio::/ and $val->isa("Bio::Root::Storable")
ref($val) =~ /^Bio::/ $val->isa("Bio::Root::Storable")
Truth table0%0/3
A and B
A= ref($val) =~ /^Bio::/B= $val->isa("Bio::Root::Storable")
ABresult
0X0
100
111
381 0 $hash{$k2} = $val->new_retrievable( %retargs );
382 }
383 0 else{ $hash{$k2} = $val }
384 }
385 0 $store_obj->{$key} = \%hash;
386 }
387  
388 # Unknown, just add to the store object regardless
389 0 else{ $store_obj->{$key} = $value }
390 }
391 12 $store_obj->retrievable(0); # Once deserialised, obj not retrievable
392 12 return $self->_freeze( $store_obj );
393 }
394  
395  
396 #----------------------------------------------------------------------
397  
398 =head2 retrieve
399  
400 Arg [1] : string; filesystem location of the state file to be retrieved
401 Function : Retrieves a stored object from disk.
402 Note that the retrieved object will be blessed into its original
403 class, and not the
404 Returntype: Bio::Root::Storable inhereting object
405 Exceptions:
406 Caller :
407 Example : my $obj = Bio::Root::Storable->retrieve( $token );
408  
409 =cut
410  
411 6 ▶sub retrieve{
Subroutine retrieve: called CC=13 SCAR=32.7
Pod documented
412 6 my( $caller, $statefile ) = @_;
413  
414 6 my $self = {};
415 6 ▶ my $class = ref( $caller ) || $caller;
Condition66%2/3
ref $caller || $caller
l!l&&r!l&&!r
240
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table66%2/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
416  
417 # Is this a call on a retrievable object?
418 6 ▶ if ( ref( $caller )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $caller and $caller->retrievable) 2 4 6
Condition66%2/3
ref $caller and $caller->retrievable
!ll&&!rl&&r
402
MC/DC50%1/2
ref $caller and $caller->retrievable
ref $caller $caller->retrievable
Truth table66%2/3
A and B
A= ref $callerB= $caller->retrievable
ABresult
0X0
100
111
419 and $caller->retrievable
420 ){
421 2 $self = $caller;
422 2 $statefile = $self->statefile;
423 }
424 6 bless( $self, $class );
425  
426 # Recover serialised object
427 6 ▶ if( ! -f $statefile ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $statefile) 0 6 6
428 0 $self->throw( "Token $statefile is not found" );
429 }
430 6 my $io = Bio::Root::IO->new( $statefile );
431 6 local $/ = undef;
432 6 my $state_str = $io->_readline('-raw'=>1);
433 # If filehandle is not stored, don't leave it open
434 6 $io->close;
435  
436 # Dynamic-load modules required by stored object
437 6 my $stored_obj;
438 my $success;
439 6 ▶ for( my $i=0; $i<10; $i++ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 10) 6 0 6
440 6 eval{ $stored_obj = $self->_thaw( $state_str ) };
441 6 ▶ if( ! $@ ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 6 0 6
442 6 $success = 1;
443 6 last;
444 }
445 0 my $package;
446 0 ▶ if( $@ =~ /Cannot restore overloading(.*)/i ){
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /Cannot restore overloading(.*)/i) 0 0 0
447 0 my $postmatch = $1; #'
448 0 ▶ if( $postmatch =~ /\(package +([\w\:]+)\)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postmatch =~ /\(package +([\w\:]+)\)/) 0 0 0
449 0 $package = $1;
450 }
451 }
452 0 ▶ if( $package ){
Branch: 1 branch
BranchTrueFalseTotal
if ($package) { } 0 0 0
453 0 eval "require $package";
454 0 ▶ $self->throw($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
455 }
456 0 else{ $self->throw($@) }
457 }
458 0 ▶ if( ! $success ){ $self->throw("maximum number of requires exceeded" ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 6 6
459  
460 6 ▶ if( ! ref( $stored_obj ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $stored_obj) 0 6 6
461 0 $self->throw( "Token $statefile returned no data" );
462 }
463 6 map{ $self->{$_} = $stored_obj->{$_} } keys %$stored_obj; # Copy hasheys
464 6 $self->retrievable(0);
465  
466 # Maintain class of stored obj
467 6 return $self;
468 }
469  
470 #----------------------------------------------------------------------
471  
472  
473 =head2 clone
474  
475 Arg [1] : none
476 Function : Returns a clone of the calling object
477 Returntype: Bio::Root::Storable inhereting object
478 Exceptions:
479 Caller :
480 Example : my $clone = $obj->clone();
481  
482 =cut
483  
484 2 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
485 2 my $self = shift;
486 2 my $frozen = $self->_freeze( $self );
487 2 return $self->_thaw( $frozen );
488 }
489  
490  
491  
492 #----------------------------------------------------------------------
493  
494 =head2 remove
495  
496 Arg [1] : none
497 Function : Clears the stored object from disk
498 Returntype: boolean
499 Exceptions:
500 Caller :
501 Example : $obj->remove();
502  
503 =cut
504  
505 4 ▶sub remove {
Subroutine remove: called CC=2 SCAR=7.0
Pod documented
506 4 my $self = shift;
507 4 ▶ if( -e $self->statefile ){
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->statefile) 4 0 4
508 4 unlink( $self->statefile );
509 }
510 4 return 1;
511 }
512  
513 #----------------------------------------------------------------------
514  
515 =head2 _freeze
516  
517 Arg [1] : variable
518 Function : Converts whatever is in the the arg into a string.
519 Uses either Storable::freeze or Data::Dumper::Dump
520 depending on the value of $Bio::Root::BINARY
521 Returntype:
522 Exceptions:
523 Caller :
524 Example :
525  
526 =cut
527  
528 14 ▶sub _freeze {
Subroutine _freeze: called CC=2 SCAR=6.9
529 14 my $self = shift;
530 14 my $data = shift;
531 14 ▶ if( $BINARY ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::Storable::BINARY) { } 7 7 14
532 7 return freeze( $data );
533 }
534 else{
535 7 $Data::Dumper::Purity = 1;
536 7 return Data::Dumper->Dump( [\$data],["*code"] );
537 }
538 }
539  
540 #----------------------------------------------------------------------
541  
542 =head2 _thaw
543  
544 Arg [1] : string
545 Function : Converts the string into a perl 'whatever'.
546 Uses either Storable::thaw or eval depending on the
547 value of $Bio::Root::BINARY.
548 Note; the string arg should have been created with
549 the _freeze method, or strange things may occur!
550 Returntype: variable
551 Exceptions:
552 Caller :
553 Example :
554  
555 =cut
556  
557 8 ▶sub _thaw {
Subroutine _thaw: called CC=4 SCAR=14.1
558 8 my $self = shift;
559 8 my $data = shift;
560 8 ▶ if( $BINARY ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::Storable::BINARY) { } 4 4 8
561 4 return thaw( $data )
562 }
563 else{
564 4 my $code;
565 4 $code = eval( $data ) ;
566 4 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
567 0 $self->throw( "eval: $@" );
568 }
569 4 ▶ ref( $code ) eq 'REF'
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq "REF" or $self->throw("Serialised string was not a scalar ref") 4 0 4
570 or $self->throw( "Serialised string was not a scalar ref" );
571 4 return $$code;
572 }
573 }
574  
575 2 1;
« Bio/SearchIO/Writer/HSPTableWriter.pm ↑ Summary Bio/SearchIO/exonerate.pm »