| 1 | package Bio::MUST::Core::Utils; | ||||||||||||||||||||
| 2 | # ABSTRACT: Utility functions for enabling multiple file processing | ||||||||||||||||||||
| 3 | 19 | $Bio::MUST::Core::Utils::VERSION = '0.252040'; | |||||||||||||||||||
| 4 | 19 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 19 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 19 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 19 | ▶ | use File::Basename; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 19 | ▶ | use Path::Class qw(file); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 19 | ▶ | use Test::Files; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 19 | ▶ | use Test::Most; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # TODO: use :filenames in some binaries | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 19 | ▶ | use Exporter::Easy ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 19 | OK => [ qw(secure_outfile :filenames :tests) ], | |||||||||||||||||||
| 17 | TAGS => [ | ||||||||||||||||||||
| 18 | filenames => [ qw(insert_suffix change_suffix append_suffix) ], | ||||||||||||||||||||
| 19 | tests => [ qw(cmp_store cmp_float) ], | ||||||||||||||||||||
| 20 | ], | ||||||||||||||||||||
| 21 | 19 | ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | ▶ | sub secure_outfile { | ||||||||||||||||||
|
Subroutine
secure_outfile: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | 2 | my $infile = shift; | |||||||||||||||||||
| 26 | 2 | my $suffix = shift; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 2 | ▶ | return insert_suffix($infile, $suffix) if defined $suffix; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | rename $infile, append_suffix($infile, '.bak') if -e $infile; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 1 | return $infile; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 6 | ▶ | sub insert_suffix { | ||||||||||||||||||
|
Subroutine
insert_suffix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 36 | 6 | my $infile = shift; | |||||||||||||||||||
| 37 | 6 | my $string = shift; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 6 | my ($filename, $directories, $suffix) = fileparse($infile, qr{\.[^.]*}xms); | |||||||||||||||||||
| 40 | 6 | return $directories . $filename . $string . $suffix; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 5 | ▶ | sub change_suffix { | ||||||||||||||||||
|
Subroutine
change_suffix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 45 | 5 | my $infile = shift; | |||||||||||||||||||
| 46 | 5 | my $suffix = shift; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 5 | my ($filename, $directories) = fileparse($infile, qr{\.[^.]*}xms); | |||||||||||||||||||
| 49 | 5 | return $directories . $filename . $suffix; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 6 | ▶ | sub append_suffix { | ||||||||||||||||||
|
Subroutine
append_suffix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 54 | 6 | my $infile = shift; | |||||||||||||||||||
| 55 | 6 | my $suffix = shift; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 6 | my ($filename, $directories) = fileparse($infile); | |||||||||||||||||||
| 58 | 6 | return $directories . $filename . $suffix; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 98 | ▶ | sub cmp_store { | ||||||||||||||||||
|
Subroutine
cmp_store: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||
| 63 | 98 | my %args = @_; | |||||||||||||||||||
| 64 | my ($obj, $method, $file, $test, $args, $filter) | ||||||||||||||||||||
| 65 | 98 | = @args{ qw(obj method file test args filter) }; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 98 | ▶ | $args //= {}; # optional hash reference | ||||||||||||||||||
|
Condition100%2/2
$args //= {}
MC/DC100%1/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # named output file | ||||||||||||||||||||
| 70 | 98 | my $outfile; | |||||||||||||||||||
| 71 | 98 | ▶ | unless ($method =~ m/\A temp_/xms) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 94 | $outfile = file('test', "my_$file"); | |||||||||||||||||||
| 73 | 94 | ▶ | ( file($outfile) )->remove if -e $outfile; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 94 | $obj->$method($outfile, $args); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # anonymous temporary file | ||||||||||||||||||||
| 78 | 98 | ▶ | $outfile //= $obj->$method($args); | ||||||||||||||||||
|
Condition66%2/3
$outfile //= $obj->$method($args)
MC/DC0%0/2
$outfile //= $obj->$method($args)
$outfile
$obj->$method($args)
Truth table66%2/3
A //= B
A= $outfileB= $obj->$method($args)
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # compare file contents | ||||||||||||||||||||
| 81 | 98 | ▶ | compare_ok( $outfile, file('test', $file), "$test: $file") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | unless $filter; | ||||||||||||||||||||
| 83 | 98 | ▶ | compare_filter_ok($outfile, file('test', $file), $filter, "$test: $file") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | if $filter; | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 98 | return; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 84 | ▶ | sub cmp_float { | ||||||||||||||||||
|
Subroutine
cmp_float: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 91 | 84 | my ($got, $expect, $epsilon, $test) = @_; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # compare got and expect to epsilon precision | ||||||||||||||||||||
| 94 | 84 | cmp_ok abs($got - $expect), '<', $epsilon, $test; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 84 | return; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 19 | 1; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||