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