StandupGenerator/Creator.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 96.6% 57 / 59 CC 4 SCAR 10.0
CC
4
Cov
96%
create_new
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« StandupGenerator/Accessor.pm ↑ Summary StandupGenerator/Helper.pm »
1 package StandupGenerator::Creator;
2  
3 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use StandupGenerator::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use StandupGenerator::Helper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our @EXPORT = qw(
8 create_new
9 );
10  
11 # Create a new standup file containing contents from the previous day's standup, then open the file for further editing
12 2 ▶sub create_new {
Subroutine create_new: called CC=4 SCAR=13.9
Pod documented
13 2 my ($path) = @_;
14 2 my $last_file = StandupGenerator::Helper::find_last_file($path);
15 2 my $last_file_path = "${path}/${last_file}";
16 2 my %last_file_identifiers = StandupGenerator::Helper::extract_identifiers($last_file);
17 2 my $last_file_sprint = $last_file_identifiers{'sprint'};
18 2 my $last_file_day = $last_file_identifiers{'day'};
19 2 my $next_file_sprint;
20 my $next_file_day;
21  
22 2 ▶ if ($last_file_day == '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_file_day == 0) { } 1 1 2
23 # Yesterday's standup was for day 10 of the last sprint, so today's standup will be for day 1 of the new sprint
24 1 $next_file_day = '01';
25 1 $next_file_sprint = $last_file_sprint + 1;
26 } else {
27 # Continue incrementing days within the current sprint
28 1 $next_day = $last_file_day + 1;
29 1 $next_file_day = "0${next_day}";
30 1 $next_file_sprint = $last_file_sprint;
31  
32 1 ▶ if ($next_file_day == '010') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_file_day == "010") 0 1 1
33 0 $next_file_day = '10';
34 }
35 }
36  
37 2 my $next_file = "s${next_file_sprint}d${next_file_day}.txt";
38 2 my $next_file_path = "${path}/${next_file}";
39  
40 # Store key data from yesterday's standup
41 2 open my $fh, '<', $last_file_path;
42 2 my $last_file_content = do { local $/; <$fh> };
43 2 close($fh);
44 2 my $file_length = length($last_file_content);
45 2 my $today_index = index($last_file_content, 'TODAY') + 6;
46 2 my $blockers_index = index($last_file_content, 'BLOCKERS') + 9;
47 2 my $today_content;
48 my $blockers_content;
49  
50 2 ▶ if ($last_file eq "s0d0.txt") {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_file eq 's0d0.txt') { } 1 1 2
51 # When creating first standup within a directory, give sections empty bullets
52 1 $today_content = "- ";
53 1 $blockers_content = "- ";
54 } else {
55 # Store yesterday's TODAY and BLOCKERS sections in order to repurpose them for today's standup
56 1 $today_content = substr($last_file_content, $today_index, $blockers_index - $today_index - 11);
57 1 $blockers_content = substr($last_file_content, $blockers_index, $file_length - $blockers_index);
58 }
59  
60 # Connect gathered pieces to form a single string with all necessary contents
61 2 my $next_file_content = "STANDUP: SPRINT ${next_file_sprint} - DAY ${next_file_day}\n\nYESTERDAY\n${today_content}\n\nTODAY\n${today_content}\n\nBLOCKERS\n${blockers_content}";
62  
63 # Create new file
64 2 open my $new_fh, '>', $next_file_path;
65 2 print $new_fh $next_file_content;
66 2 close($new_fh);
67  
68 # Open new file
69 2 StandupGenerator::Accessor::open_one($path, $next_file_sprint, $next_file_day);
70  
71 2 return $next_file;
72 }
73  
74 3 1;
75  
76 __END__
« StandupGenerator/Accessor.pm ↑ Summary StandupGenerator/Helper.pm »