Skip to content

Commit

Permalink
more IO changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cjfields committed Oct 31, 2014
1 parent b753e66 commit d4294c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 58 deletions.
51 changes: 25 additions & 26 deletions lib/Bio/Role/Temp.pm6
Expand Up @@ -4,15 +4,37 @@ use File::Temp;

role Bio::Role::Temp;

has Bool $save-tempfiles = False;
has Bool $.cleanup-tmpdir = True;
has Bool $.cleanup-tmpfiles = True;
has @!tmpdirs;
my $tmpcounter = 0;

method tmpfile(*%args) {
if ?$save-tempfiles && (%args{'unlink'}:exists) {

# local passed arguments should override the global settings, not ignore them

if %args{'unlink'}:!exists {
%args{'unlink'} = False ;
}
tempfile(|%args);
}

method tmpdir(Bool :$cleanup) {
$!cleanup-tmpdir = $cleanup if $cleanup;
my $tdir = $*SPEC.catfile( $*TMPDIR,
sprintf("dir_%s-%s-%s",
%*ENV{'USER'} || 'unknown',
$*PID,
$tmpcounter++));
mkdir($tdir, 0o755);
@!tmpdirs.push: $tdir;
return $tdir;
}

submethod DESTROY {
say "Destroyed!!!";
}

#sub tempfile {
# my ($self, @args) = @_;
# my ($tfh, $file);
Expand Down Expand Up @@ -87,28 +109,5 @@ method tmpfile(*%args) {
# return wantarray ? ($tfh,$file) : $tfh;
#}

method tmpdir {
...
}

#sub tempdir {
# my ($self, @args) = @_;
# if ($FILETEMPLOADED && File::Temp->can('tempdir')) {
# return File::Temp::tempdir(@args);
# }
#
# # we have to do this ourselves, not good
# # we are planning to cleanup temp files no matter what
# my %params = @args;
# print "cleanup is " . $params{CLEANUP} . "\n";
# $self->{'_cleanuptempdir'} = ( defined $params{CLEANUP} &&
# $params{CLEANUP} == 1);
# my $tdir = $self->catfile( $TEMPDIR,
# sprintf("dir_%s-%s-%s",
# $ENV{USER} || 'unknown',
# $$,
# $TEMPCOUNTER++));
# mkdir($tdir, 0755);
# push @{$self->{'_rootio_tempdirs'}}, $tdir;
# return $tdir;
#}

32 changes: 0 additions & 32 deletions t/Role/IO.t
Expand Up @@ -47,36 +47,4 @@ is($in.mode, 'r');
is(MyIO.catfile('a', 'b', 'c'), $*SPEC.catfile('a', 'b', 'c'), 'catfile');
is(MyIO.catdir('a', 'b', 'c'), $*SPEC.catdir('a', 'b', 'c'), 'catdir');

#my $in = Bio::SeqIO.new(format => 'fasta');
#
#is($in.format, 'fasta', 'format');
#
#dies_ok { $in.format = 'fastq' }, 'readonly';
#
## no version or variant (these are optional)
#ok($in.format-version ~~ Any, 'version');
#ok($in.format-variant ~~ Any, 'variant');
#
## explicit
#$in = Bio::SeqIO.new(format => 'fasta',
# format-version => 1.0,
# format-variant => 'old');
#
#is($in.format, 'fasta', 'format');
#is($in.format-version, 1.0, 'version');
#dies_ok { $in.format-version = 2.0 }, 'readonly';
#dies_ok { $in.format-variant = 'new'}, 'readonly';
#
#is($in.format-variant, 'old', 'variant');
#
## format-variant
#$in = Bio::SeqIO.new(format => 'fasta-old',
# format-version => 1.0);
#
#is($in.format, 'fasta', 'format');
#is($in.format-version, 1.0, 'version');
#is($in.format-variant, 'old', 'variant');
#
#dies_ok {Bio::SeqIO.new(format => "foo")}, 'dies with an unknown format';
#
done();

0 comments on commit d4294c6

Please sign in to comment.