| 1 | package App::TimelogTxt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use App::CmdDispatch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Getopt::Long qw(:config posix_default); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use App::TimelogTxt::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use App::TimelogTxt::Day; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use App::TimelogTxt::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use App::TimelogTxt::Event; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Initial configuration information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my %config = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | editor => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | dir => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | defcmd => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $config_file = _normalize_path( '~/.timelogrc' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Dispatch table for commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | my %commands = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'start' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | code => \&start_event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | clue => 'start {event description}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | abstract => 'Start timing a new event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | help => 'Stop the current event and start timing a new event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | App::TimelogTxt::Utils::STOP_CMD() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | code => sub { my $app = shift; log_event( $app, App::TimelogTxt::Utils::STOP_CMD() ); }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | clue => App::TimelogTxt::Utils::STOP_CMD(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | abstract => 'Stop timing the current event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | help => 'Stop timing the current event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'init' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | code => \&init_timelog, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | clue => 'init [directory]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | abstract => 'Create the timelog directory and configuration.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | help => 'Create the directory and configuration file used by timelog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | if they do not already exist.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'push' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | code => \&push_event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | clue => 'push {event description}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | abstract => 'Save the current event and start timing new.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | help => 'Save the current event on stack and start timing new event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'pop' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | code => \&pop_event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | clue => 'pop', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | abstract => 'Return to last pushed event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | help => 'Stop last event and restart top event on stack.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 'drop' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | code => \&drop_event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | clue => 'drop [all|{n}]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | abstract => 'Drop items from stack.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | help => 'Drop one or more events from top of event stack, or all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | if argument supplied.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 'ls' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | code => \&list_events, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | clue => 'ls [date]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | abstract => 'List events.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | help => 'List events for the specified day. Default to today.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 'lsproj' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | code => \&list_projects, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | clue => 'lsproj', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | abstract => 'List known projects.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | help => 'List known projects.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 'lstk' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | code => \&list_stack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | clue => 'lstk', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | abstract => 'Display items on the stack.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | help => 'Display items on the stack.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'edit' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | code => \&edit_logfile, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | clue => 'edit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | abstract => 'Edit the timelog file.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | help => 'Open the timelog file in the current editor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'report' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | code => \&daily_report, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | clue => 'report [date [end date]] [project regexes]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | abstract => 'Task report.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | help => 'Display a report for the specified days and projects.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'summary' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | code => \&daily_summary, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | clue => 'summary [date [end date]] [project regexes]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | abstract => 'Short summary report.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | help => q{Display a summary of the appropriate days' projects.}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 'hours' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | code => \&report_hours, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | clue => 'hours [date [end date]] [project regexes]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | abstract => 'Hours report.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | help => q{Display the hours worked for each of the appropriate days | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | and projects.}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'curr' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | code => \¤t_event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | clue => 'curr', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | abstract => 'Display current event.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | help => q{Display the current event (if any) and the time since the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | event started.}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # Sub class of App::CmdDispatch that initializes configuration information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # specific to this program. It also provides access to that configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | package Timelog::CmdDispatch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | use base 'App::CmdDispatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = App::CmdDispatch::new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->{_timelog_out_fh} = \*STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub _logfile { return $_[0]->get_config()->{'logfile'}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_logfile: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub _stackfile { return $_[0]->get_config()->{'stackfile'}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stackfile: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub _out_fh { return $_[0]->{_timelog_out_fh}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_out_fh: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Support injection of an output filehandle for testing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub _set_out_fh { return $_[0]->{_timelog_out_fh} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_out_fh: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $config = $self->get_config(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $config->{editor} ||= $config{editor} || $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vim'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/11
$config->{"editor"} ||= $config{"editor"} || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim"
$config{'editor'} || $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vim'
$config{"editor"} or $ENV{"VISUAL"} or $ENV{"EDITOR"}
$config{"editor"} or $ENV{"VISUAL"}
MC/DC0%0/4
$config->{"editor"} ||= $config{"editor"} || $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim"
$config->{"editor"}
$config{"editor"}
$ENV{"VISUAL"}
$ENV{"EDITOR"}
Truth table0%0/5
A ||= B or C or D
A= $config->{"editor"}B= $config{"editor"}C= $ENV{"VISUAL"}D= $ENV{"EDITOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $config->{dir} ||= $config{dir} || App::TimelogTxt::_normalize_path( '~/timelog' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$config->{"dir"} ||= $config{"dir"} || App::TimelogTxt::_normalize_path("~/timelog")
$config{'dir'} || App::TimelogTxt::_normalize_path('~/timelog')
MC/DC0%0/3
$config->{"dir"} ||= $config{"dir"} || App::TimelogTxt::_normalize_path("~/timelog")
$config->{"dir"}
$config{'dir'}
App::TimelogTxt::_normalize_path('~/timelog')
Truth table0%0/4
A ||= B || C
A= $config->{"dir"}B= $config{'dir'}C= App::TimelogTxt::_normalize_path('~/timelog')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $config->{defcmd} ||= $config{defcmd} || App::TimelogTxt::Utils::STOP_CMD(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$config->{"defcmd"} ||= $config{"defcmd"} || App::TimelogTxt::Utils::STOP_CMD()
$config{'defcmd'} || App::TimelogTxt::Utils::STOP_CMD()
MC/DC0%0/3
$config->{"defcmd"} ||= $config{"defcmd"} || App::TimelogTxt::Utils::STOP_CMD()
$config->{"defcmd"}
$config{'defcmd'}
App::TimelogTxt::Utils::STOP_CMD()
Truth table0%0/4
A ||= B || C
A= $config->{"defcmd"}B= $config{'defcmd'}C= App::TimelogTxt::Utils::STOP_CMD()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $config->{dir} = App::TimelogTxt::_normalize_path( $config->{'dir'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | foreach my $d ( [qw/logfile timelog.txt/], [qw/stackfile stack.txt/] ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $config->{ $d->[0] } = "$config->{'dir'}/$d->[1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | "dir=s" => \$config{'dir'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | "editor=s" => \$config{'editor'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | "conf=s" => \$config_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $options = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | config => (-f $config_file ? $config_file : undef), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | default_commands => 'help shell', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 'help:post_hint' => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | "\nwhere [date] is an optional string specifying a date of the form YYYY-MM-DD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | or a day name: yesterday, today, or sunday .. saturday and [project regexes] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | is a list of strings of regular expressions matching project names.\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 'help:post_help' => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | "\nwhere [date] is an optional string specifying a date of the form YYYY-MM-DD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | or a day name: yesterday, today, or sunday .. saturday and [project regexes] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | is a list of strings of regular expressions matching project names.\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $app = Timelog::CmdDispatch->new( \%commands, $options ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Handle default command if none specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | @ARGV = split / /, $app->get_config()->{'defcmd'} unless @ARGV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $app->run( @ARGV ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Command handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | sub init_timelog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_timelog: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my ($app, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $config = $app->get_config(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $dir //= $config->{'dir'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$dir //= $config->{"dir"}
MC/DC0%0/2
$dir //= $config->{"dir"}
$dir
$config->{"dir"}
Truth table0%0/3
A //= B
A= $dirB= $config->{"dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $dir = _normalize_path( $dir ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | File::Path::mkpath( $dir ) unless -d $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | unless( -f $config_file ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | open my $fh, '>', $config_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # don't supply the editor value, default to the environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | print {$fh} <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | dir=$dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | defcmd=$config->{defcmd} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | [alias] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | print "timelog initialized\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | sub log_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_event: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $task = "@_"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if( App::TimelogTxt::Utils::is_stop_cmd( $task ) || App::TimelogTxt::Utils::has_project( $task ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
App::TimelogTxt::Utils::is_stop_cmd($task) or App::TimelogTxt::Utils::has_project($task)
MC/DC0%0/2
App::TimelogTxt::Utils::is_stop_cmd($task) or App::TimelogTxt::Utils::has_project($task)
App::TimelogTxt::Utils::is_stop_cmd($task)
App::TimelogTxt::Utils::has_project($task)
Truth table0%0/3
A or B
A= App::TimelogTxt::Utils::is_stop_cmd($task)B= App::TimelogTxt::Utils::has_project($task)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | open my $fh, '>>', $app->_logfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $event = App::TimelogTxt::Event->new( $task, time ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | print {$fh} $event->to_string, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | die "Event has no project.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | sub edit_logfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_logfile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my ( $app ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | system $app->get_config()->{'editor'}, $app->_logfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | sub list_events | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_events: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my ( $app, $day ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $stamp = App::TimelogTxt::Utils::day_stamp( $day ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | _each_logline( $app, sub { print if 0 == index $_, $stamp; } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | sub list_projects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_projects: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ( $app ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my %projects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | _each_logline( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | $app, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my ( @projs ) = m/\+(\S+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | @projects{@projs} = ( 1 ) x @projs if @projs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | print "$_\n" foreach sort keys %projects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | sub daily_report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
daily_report: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ( $app, @filters ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $summaries = extract_day_tasks( $app, @filters ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | foreach my $summary ( @{$summaries} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $summary->print_day_detail( $app->_out_fh ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub daily_summary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
daily_summary: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my ( $app, @filters ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $summaries = extract_day_tasks( $app, @filters ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | foreach my $summary ( @{$summaries} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $summary->print_day_summary( $app->_out_fh ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | sub report_hours | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_hours: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my ( $app, @filters ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $summaries = extract_day_tasks( $app, @filters ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | foreach my $summary ( @{$summaries} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $summary->print_hours( $app->_out_fh ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | sub start_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my ( $app, @event ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | log_event( $app, @event ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | sub push_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my ( $app, @event ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $stack = _stack( $app ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $stack->push( _get_last_event( $app ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | log_event( $app, @event ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | sub pop_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pop_event: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ( $app ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | return unless -f $app->_stackfile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $stack = _stack( $app ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $event = $stack->pop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | die "Event stack is empty.\n" unless $event; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | log_event( $app, $event ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | sub drop_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_event: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ( $app, $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | return unless -f $app->_stackfile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $stack = _stack( $app ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $stack->drop( $arg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | sub list_stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_stack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | return unless -f $app->_stackfile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $stack = _stack( $app ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $stack->list( $app->_out_fh ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | sub current_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_event: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $fh = $app->_out_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $event = _get_last_full_event( $app ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if( $event->is_stop ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | print {$fh} "Not in event.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # Use day summary object to get duration and to report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $summary = App::TimelogTxt::Day->new( $event->stamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $summary->start_task( $event ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $summary->update_dur( $event, time ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | print {$fh} $event->to_string, "\nDuration: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $summary->print_duration( $fh ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # Extract the daily events from the timelog.txt file and generate the list of Day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # objects that encapsulates them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | sub extract_day_tasks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_day_tasks: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my ( $app, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my ($stamp, $estamp, $pstamp, @filters) = _process_extraction_args( @args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my ( $summary, $last, @summaries ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $prev_stamp = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | open my $fh, '<', $app->_logfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $file = App::TimelogTxt::File->new( $fh, $pstamp, $estamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | while( defined( my $line = $file->readline ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $event; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $event = App::TimelogTxt::Event->new_from_line( $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if( $prev_stamp ne $event->stamp ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $new_stamp = $event->stamp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $new_summary = App::TimelogTxt::Day->new( $new_stamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if( $summary and !$summary->is_complete() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$summary and not $summary->is_complete
MC/DC0%0/2
$summary and not $summary->is_complete
$summary
not $summary->is_complete
Truth table0%0/3
A and not(B)
A= $summaryB= not $summary->is_complete
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $summary->close_day( $last ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # Need to build a new last item beginning at midnight for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Previous event. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $start = $summary->day_end()+1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | $last = App::TimelogTxt::Event->new( $last->task(), $start ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $new_summary->start_task( $last ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $summary = $new_summary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | push @summaries, $summary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $prev_stamp = $new_stamp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $summary->update_dur( $last, $event->epoch ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $summary->start_task( $event ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $last = ($event->is_stop() ? undef : $event ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # If the first summary is the day before we were supposed to report, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # drop it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | shift @summaries if @summaries && $summaries[0]->date_stamp() eq $pstamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@summaries and $summaries[0]->date_stamp eq $pstamp
MC/DC0%0/2
@summaries and $summaries[0]->date_stamp eq $pstamp
@summaries
$summaries[0]->date_stamp eq $pstamp
Truth table0%0/3
A and B
A= @summariesB= $summaries[0]->date_stamp eq $pstamp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | return [] unless $summary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $end_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if( $summary->is_complete() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $summary->update_dur( $last, $end_time ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $datestamp = $summary->date_stamp() || $stamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$summary->date_stamp || $stamp
MC/DC0%0/2
$summary->date_stamp || $stamp
$summary->date_stamp
$stamp
Truth table0%0/3
A || B
A= $summary->date_stampB= $stamp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if( App::TimelogTxt::Utils::is_today( $datestamp ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $end_time = time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $summary->update_dur( $last, $end_time ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $summary->close_day( $last ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $end_time = App::TimelogTxt::Utils::stamp_to_localtime( $datestamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | return if $summary->is_empty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return _filter_summaries( \@filters, \@summaries ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | sub _filter_summaries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_summaries: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my ( $filters, $summaries ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return $summaries unless @{$filters}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $filter = join( '|', map { "(?:$_)" } @{$filters} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $filter_re = qr/$filter/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | grep { $_->has_tasks } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | map { $_->day_filtered_by_project( $filter_re ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | @{$summaries} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | sub _process_extraction_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_extraction_args: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my ($day, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # First argument is always the day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my $stamp = App::TimelogTxt::Utils::day_stamp( $day ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | die "No day provided.\n" unless defined $stamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $eday = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | my $estamp = App::TimelogTxt::Utils::day_end( $eday ? App::TimelogTxt::Utils::day_stamp( $eday ) : $stamp ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | if( !defined $estamp ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $estamp = App::TimelogTxt::Utils::day_end( $stamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | unshift @args, $eday if $eday; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # I need to start one day before to deal with the possibility that first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # task was held over midnight. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $pstamp = App::TimelogTxt::Utils::prev_stamp( $stamp ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return ($stamp, $estamp, $pstamp, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # Utility functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Find user's home directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | sub _home | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_home: called CC=5 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | ▶ | return $ENV{HOME} if defined $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if( $^O eq 'MSWin32' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | return "$ENV{HOMEDRIVE}$ENV{HOMEPATH}" if defined $ENV{HOMEPATH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | return $ENV{USERPROFILE} if defined $ENV{USERPROFILE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | return '/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Resolve ~ notation and convert to an absolute path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | sub _normalize_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | my $home = _home(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | $path =~ s/~/$home/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | return $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | sub _each_logline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_each_logline: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my ( $app, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | open my $fh, '<', $app->_logfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | $code->() while( <$fh> ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | sub _stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stack: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | require App::TimelogTxt::Stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | return App::TimelogTxt::Stack->new( $app->_stackfile ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | sub _get_last_full_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_last_full_event: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my ( $app ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $event_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | _each_logline( $app, sub { $event_line = $_; } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | return App::TimelogTxt::Event->new_from_line( $event_line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | sub _get_last_event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_last_event: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $event = _get_last_full_event( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | return $event->task; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||