line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::JobLog::Command::last; |
2
|
|
|
|
|
|
|
$App::JobLog::Command::last::VERSION = '1.039'; |
3
|
|
|
|
|
|
|
# ABSTRACT: show details of last recorded event |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1967
|
use Modern::Perl; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
6
|
2
|
|
|
2
|
|
230
|
use App::JobLog -command; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
7
|
2
|
|
|
|
|
10
|
use Class::Autouse qw( |
8
|
|
|
|
|
|
|
App::JobLog::Log |
9
|
|
|
|
|
|
|
App::JobLog::Command::summary |
10
|
2
|
|
|
2
|
|
758
|
); |
|
2
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub execute { |
13
|
12
|
|
|
12
|
1
|
73
|
my ( $self, $opt, $args ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# construct event test |
16
|
12
|
100
|
|
|
|
30
|
my %must = map { $_ => 1 } @{ $opt->tag || [] }; |
|
8
|
|
|
|
|
73
|
|
|
12
|
|
|
|
|
48
|
|
17
|
12
|
100
|
|
|
|
97
|
my %mustnt = map { $_ => 1 } @{ $opt->without || [] }; |
|
8
|
|
|
|
|
59
|
|
|
12
|
|
|
|
|
57
|
|
18
|
|
|
|
|
|
|
my $test = sub { |
19
|
20
|
|
|
20
|
|
35
|
my $event = shift; |
20
|
20
|
|
|
|
|
26
|
my @tags = @{ $event->tags }; |
|
20
|
|
|
|
|
70
|
|
21
|
20
|
|
|
|
|
47
|
my %tags = map { $_ => 1 } @tags; |
|
22
|
|
|
|
|
72
|
|
22
|
20
|
|
|
|
|
41
|
my $good = 1; |
23
|
20
|
100
|
|
|
|
55
|
if (%must) { |
24
|
10
|
100
|
|
|
|
39
|
if ( $opt->any ) { |
25
|
4
|
|
|
|
|
25
|
$good = 0; |
26
|
4
|
|
|
|
|
11
|
for my $tag (@tags) { |
27
|
4
|
100
|
|
|
|
27
|
if ( $must{$tag} ) { |
28
|
3
|
|
|
|
|
10
|
$good = 1; |
29
|
3
|
|
|
|
|
8
|
last; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
6
|
|
|
|
|
40
|
for my $tag ( keys %must ) { |
35
|
8
|
100
|
|
|
|
25
|
unless ( $tags{$tag} ) { |
36
|
3
|
|
|
|
|
5
|
$good = 0; |
37
|
3
|
|
|
|
|
7
|
last; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
20
|
100
|
100
|
|
|
143
|
if ( $good && %mustnt ) { |
43
|
10
|
100
|
|
|
|
55
|
if ( $opt->some ) { |
44
|
4
|
|
|
|
|
32
|
$good = 0; |
45
|
4
|
|
|
|
|
17
|
for my $tag ( keys %mustnt ) { |
46
|
5
|
100
|
|
|
|
25
|
unless ( $tags{$tag} ) { |
47
|
3
|
|
|
|
|
5
|
$good = 1; |
48
|
3
|
|
|
|
|
5
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
6
|
|
|
|
|
35
|
for my $tag (@tags) { |
54
|
6
|
100
|
|
|
|
27
|
if ( $mustnt{$tag} ) { |
55
|
4
|
|
|
|
|
17
|
$good = 0; |
56
|
4
|
|
|
|
|
9
|
last; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
20
|
|
|
|
|
97
|
return $good; |
62
|
12
|
|
|
|
|
139
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# find event |
65
|
12
|
|
|
|
|
159
|
my ( $i, $count, $e ) = ( App::JobLog::Log->new->reverse_iterator, 0 ); |
66
|
12
|
|
|
|
|
145
|
while ( $e = $i->() ) { |
67
|
20
|
|
|
|
|
60
|
$count++; |
68
|
20
|
100
|
|
|
|
55
|
last if $test->($e); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
12
|
100
|
|
|
|
45
|
if ($e) { |
72
|
11
|
|
|
|
|
35
|
my $start = $e->start->strftime('%F at %H:%M:%S %p'); |
73
|
11
|
100
|
|
|
|
1275
|
my $end = $e->is_open ? 'now' : $e->end->strftime('%F at %H:%M:%S %p'); |
74
|
11
|
|
|
|
|
512
|
$opt->{merge} = 'no_merge'; |
75
|
11
|
|
|
|
|
137
|
App::JobLog::Command::summary->execute( $opt, ["$start - $end"] ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
1
|
50
|
|
|
|
13
|
say $count ? 'no matching event' : 'empty log'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
12
|
|
|
12
|
1
|
27713
|
sub usage_desc { '%c ' . __PACKAGE__->name } |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
1
|
0
|
sub abstract { 'describe the last task recorded' } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub options { |
87
|
|
|
|
|
|
|
return ( |
88
|
|
|
|
|
|
|
[ |
89
|
12
|
|
|
12
|
0
|
151
|
'tag|t=s@', |
90
|
|
|
|
|
|
|
'find the last event with all of these tags; ' |
91
|
|
|
|
|
|
|
. 'multiple tags may be specified' |
92
|
|
|
|
|
|
|
], |
93
|
|
|
|
|
|
|
[ 'any|a', 'require only that one of the --tag tags be present' ], |
94
|
|
|
|
|
|
|
[ |
95
|
|
|
|
|
|
|
'without|w=s@', |
96
|
|
|
|
|
|
|
'find the last event which does not have any of these tags; ' |
97
|
|
|
|
|
|
|
. 'multiple tags may be specified' |
98
|
|
|
|
|
|
|
], |
99
|
|
|
|
|
|
|
[ |
100
|
|
|
|
|
|
|
'some|s', 'require only that some one of the --without tags be absent' |
101
|
|
|
|
|
|
|
], |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |