JobLog/Command/vacation.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 134 CC 11 SCAR 33.7
CC
11
Cov
0%
validate
72.0
execute
12.0
_show
6.0
CRAP 29.2
1 package App::JobLog::Command::vacation;
2 $App::JobLog::Command::vacation::VERSION = '1.042';
3 # ABSTRACT: controller for vacation dates
4  
5 use Modern::Perl;
6 use App::JobLog -command;
7 use autouse 'App::JobLog::TimeGrammar' => qw(parse);
8 use autouse 'App::JobLog::Vacation::Period' => qw(
9 FLEX
10 FIXED
11 ANNUAL
12 MONTHLY
13 );
14 use Class::Autouse qw(App::JobLog::Vacation);
15 no if $] >= 5.018, warnings => "experimental::smartmatch";
16  
17 sub execute {
18 my ( $self, $opt, $args ) = @_;
19  
20 my $vacation = App::JobLog::Vacation->new;
21 if ( $opt->modification ) {
22 eval {
23 for ( $opt->modification )
24 {
25 when ('add') {
26 my ( $s, $e ) = parse( $opt->add );
27 my $repeats;
28 for ( $opt->{repeat} || '' ) {
29 when ('annual') { $repeats = ANNUAL }
30 when ('monthly') { $repeats = MONTHLY }
31 default { $repeats = 0 };
32 }
33 my $flexibility;
34 for ( $opt->{flexibility} || '' ) {
35 when ('fixed') { $flexibility = FIXED }
36 when ('flex') { $flexibility = FLEX }
37 default { $flexibility = 0 };
38 }
39 $vacation->add(
40 description => join( ' ', @$args ),
41 time => $s,
42 end => $e,
43 repeats => $repeats,
44 type => $flexibility,
45 tags => $opt->{tag} || [],
46 );
47 }
48 when ('remove') {
49 $vacation->remove( $opt->remove );
50 }
51 }
52 };
53 $self->usage_error($@) if $@;
54 }
55 _show($vacation);
56 $vacation->close;
57 }
58  
59 sub _show {
60 my ($vacation) = @_;
61 my $lines = $vacation->show;
62 if (@$lines) {
63 print $_ for @$lines;
64 }
65 else {
66 say 'no vacation times recorded';
67 }
68 }
69  
70 sub usage_desc { '%c ' . __PACKAGE__->name . ' %o [<description>]' }
71  
72 sub abstract { 'list or define days off' }
73  
74 sub options {
75 return (
76 [ 'list|l', 'show all vacation times recorded', ],
77 [
78 'flexibility' => hidden => {
79 one_of => [
80 [
81 'flex|f',
82 'add sufficient vacation time to complete workday; this is recorded with the "flex" tag'
83 ],
84 [
85 'fixed|x',
86 'a particular period of time during the day that should be marked as vacation; '
87 . 'this is in effect a special variety of work time, since it has a definite start and duration'
88 ],
89 ]
90 }
91 ],
92 [ 'tag|t=s@', 'tag vacation time; e.g., -a yesterday -t float' ],
93 [
94 'repeat' => 'hidden' => {
95 one_of => [
96 [ 'annual', 'vacation period repeats annually' ],
97 [ 'monthly', 'vacation period repeats monthly' ],
98 ]
99 }
100 ],
101 [
102 'modification' => 'hidden' => {
103 one_of => [
104 [ 'add|a=s', 'add date or range; e.g., -a "May 17, 1951"' ],
105 [
106 'remove|r=i',
107 'remove period with given index from list (see --list); e.g., -r 1'
108 ],
109 ]
110 }
111 ]
112 );
113 }
114  
115 sub validate {
116 my ( $self, $opt, $args ) = @_;
117  
118 if ( $opt->modification ) {
119 $self->usage_error('either list or modify') if $opt->list;
120 $self->usage_error('no description provided')
121 if $opt->modification eq 'add'
122 && !@$args;
123 }
124 else {
125 $self->usage_error('--tag requires that you add a date')
126 if $opt->tag;
127 $self->usage_error('--annual and --monthly require --add')
128 if $opt->repeat;
129 $self->usage_error('either list or modify') unless $opt->list;
130 $self->usage_error('both --flex and --fixed require --add')
131 if $opt->flexibility;
132 }
133 }
134  
135 1;
136  
137 __END__