StandupGenerator/Helper.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 100% 29 / 29 CC 2 SCAR 4.1
CC
2
Cov
100%
find_last_file
2.0
BEGIN
1.0
extract_identifiers
1.0
CRAP 1.5
« StandupGenerator/Creator.pm ↑ Summary StandupGenerator.pm »
1 package StandupGenerator::Helper;
2  
3 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our @EXPORT = qw(
6 find_last_file
7 extract_identifiers
8 );
9  
10 # Determine last file in a directory after sorting them alphabetically
11 4 ▶sub find_last_file {
Subroutine find_last_file: called CC=2 SCAR=6.9
Pod documented
12 4 my ($path) = @_;
13 4 opendir my $dir, $path;
14 4 my @files = readdir $dir;
15 4 closedir $dir;
16 4 my @sorted = sort @files;
17 4 my $files_length = scalar(@files);
18 4 my $last_file = $sorted[$files_length - 1];
19  
20 4 ▶ if (index($last_file, '.txt') == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($last_file, ".txt") == -1) 2 2 4
21 # When no .txt files exist in the directory, assume standups need to be initialized, so set the last file as a dummy
22 2 $last_file = 's0d0.txt';
23 }
24  
25 4 return $last_file;
26 }
27  
28 # Get sprint and day numbers for a standup given its file name
29 4 ▶sub extract_identifiers {
Subroutine extract_identifiers: called CC=1 SCAR=0.0
Pod documented
30 4 my ($file) = @_;
31 4 my $file_size = length($file) - 4;
32 4 my $file_d_index = index($file, 'd');
33 4 my $file_sprint = substr($file, 1, $file_d_index - 1);
34 4 my $file_day = substr($file, $file_size - 1, 1);
35
36 4 my %identifiers = (
37 sprint => $file_sprint,
38 day => $file_day,
39 );
40  
41 4 return %identifiers;
42 }
43  
44 3 1;
45  
46 __END__
« StandupGenerator/Creator.pm ↑ Summary StandupGenerator.pm »