| 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
| |||||||||||
| 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__ | ||||||||||