lib/App/Sandy/Role/IO.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« lib/App/Sandy/Role/Digest.pm ↑ Summary lib/App/Sandy/Role/ParseArgv.pm »
1 package App::Sandy::Role::IO;
2 # ABSTRACT: Input and output custom wrappers.
3  
4 1 ▶use App::Sandy::Base 'role';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use App::Sandy::BGZF;
6 use IO::Compress::Gzip '$GzipError';
7 use PerlIO::gzip;
8  
9 our $VERSION = '0.25'; # VERSION
10  
11 sub with_open_r {
12 my ($self, $file) = @_;
13  
14 my $fh;
15 my $mode = $file =~ /\.gz$/ ? "<:gzip" : "<";
16  
17 open $fh, $mode => $file
18 or die "Not possible to read $file: $!\n";
19  
20 return $fh;
21 }
22  
23 sub with_open_w {
24 my ($self, $file, $level) = @_;
25  
26 my $fh;
27  
28 if ($level) {
29 $fh = IO::Compress::Gzip->new($file, -Level => $level)
30 or die "Not possible to create $file: $GzipError\n";
31 } else {
32 open $fh, '>' => $file
33 or die "Not possible to create $file: $!\n";
34 }
35  
36 return $fh;
37 }
38  
39 sub with_open_a {
40 my ($self, $file) = @_;
41  
42 open my $fh, '>>' => $file
43 or die "Not possible to append to $file: $!\n";
44  
45 return $fh;
46 }
47  
48 sub with_open_bam_w {
49 my ($self, $file, $level) = @_;
50 my $fh = App::Sandy::BGZF->new_filehandle($file, $level);
51 return $fh;
52 }
53  
54 __END__
« lib/App/Sandy/Role/Digest.pm ↑ Summary lib/App/Sandy/Role/ParseArgv.pm »