File Coverage

blib/lib/App/bif/work.pm
Criterion Covered Total %
statement 21 50 42.0
branch 0 16 0.0
condition 0 6 0.0
subroutine 7 7 100.0
pod 1 1 100.0
total 29 80 36.2


line stmt bran cond sub pod time code
1             package App::bif::work;
2 1     1   619 use strict;
  1         3  
  1         25  
3 1     1   5 use warnings;
  1         2  
  1         37  
4 1     1   6 use Bif::Mo;
  1         1  
  1         7  
5 1     1   755 use DBIx::ThinSQL qw/concat coalesce qv/;
  1         27889  
  1         9  
6 1     1   812 use IO::Prompt::Tiny qw/prompt/;
  1         525  
  1         68  
7 1     1   5 use Time::Piece;
  1         3  
  1         11  
8              
9             our $VERSION = '0.1.5_6';
10             extends 'App::bif';
11              
12             sub run {
13 1     1 1 3 my $self = shift;
14 1         4 my $opts = $self->opts;
15 1         9 my $work = $self->current_work;
16 0           my $dbw = $self->dbw;
17              
18             # Nothing specified, just display the status
19 0 0         if ( !exists $opts->{id} ) {
20 0 0         if ($work) {
21 0 0         if ( $work->{kind} eq 'topic' ) {
22             printf "working %s %s %s (since %s)\n (%s)\n", $work->{kind},
23             $work->{path},
24             $self->s2hm( time - $work->{start} ),
25             localtime( $work->{start} )->strftime('%Y-%m-%d %H:%M:%S'),
26 0           $work->{title};
27             }
28             else {
29             printf "working %s %s %s (since %s)\n", $work->{kind},
30             $work->{path},
31             $self->s2hm( time - $work->{start} ),
32 0           localtime( $work->{start} )->strftime('%Y-%m-%d %H:%M:%S'),
33             ;
34             }
35 0           return $self->ok('Working');
36             }
37 0           print "Not currently working a node.\n";
38 0           return $self->ok('NoWork');
39             }
40              
41 0           my $epoch = $self->datetime2s( $opts->{at} );
42              
43             # Stop work
44 0 0         if ( $opts->{id} eq '-' ) {
45              
46             # But only if we were actually working
47 0 0         if ($work) {
48             $self->stop_work(
49             stop => $epoch,
50             stop_comment => $opts->{comment},
51 0           );
52             printf "stopped working %s %s after %s\n", $work->{kind},
53             $work->{path},
54 0           $self->s2hm( $epoch - $work->{start} );
55 0           return $self->ok('StopWork');
56             }
57              
58 0           print "Not currently working a node.\n";
59 0           return $self->ok('NoWork');
60             }
61              
62             # Check validity of ID
63 0           my $info = $self->get_node( $opts->{id} );
64 0           $opts->{id} = $info->{id};
65              
66             # Maybe complain if we are working something else
67 0 0         if ($work) {
68             return $self->err( 'WorkOther', "working %s %s [%s] since %s",
69             $work->{kind}, $work->{node_id}, $work->{path},
70             scalar localtime( $work->{start} ) )
71 0 0         unless $opts->{force};
72              
73 0   0       $opts->{comment} ||= prompt( 'Comment:', '' );
74 0           $self->stop_work( stop => $epoch - 1 );
75             printf "stopped working %s %s after %s\n", $work->{kind},
76             $work->{path},
77 0           $self->s2hm( $epoch - $work->{start} );
78             }
79             else {
80 0   0       $opts->{comment} ||= prompt( 'Comment:', '' );
81             }
82              
83             # Finally, start the new work
84             $self->start_work(
85             node_id => $info->{id},
86             start => $epoch,
87             start_comment => $opts->{comment},
88 0 0         billable => $opts->{not_billable} ? 0 : 1,
89             );
90              
91 0           $work = $self->current_work;
92              
93             printf "working %s %s since %s\n", $work->{kind},
94             $work->{path},
95 0           scalar localtime( $work->{start} );
96              
97 0           return $self->ok('StartWork');
98             }
99              
100             1;
101             __END__