| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::JobLog::Command::modify; | 
| 2 |  |  |  |  |  |  | $App::JobLog::Command::modify::VERSION = '1.040'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: modify last logged event | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 2 |  |  | 2 |  | 1578 | use App::JobLog -command; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 6 | 2 |  |  | 2 |  | 721 | use Modern::Perl; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 7 | 2 |  |  | 2 |  | 213 | use Class::Autouse qw(App::JobLog::Log); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 8 | 2 |  |  | 2 |  | 110 | no if $] >= 5.018, warnings => "experimental::smartmatch"; | 
|  | 2 |  |  |  |  | 9 |  | 
|  | 2 |  |  |  |  | 15 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub execute { | 
| 11 | 0 |  |  | 0 | 1 |  | my ( $self, $opt, $args ) = @_; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 0 |  |  |  |  |  | my $log = App::JobLog::Log->new; | 
| 14 | 0 |  |  |  |  |  | my ( $e, $i ) = $log->last_event; | 
| 15 | 0 | 0 |  |  |  |  | $self->usage_error('empty log') unless $e; | 
| 16 | 0 |  |  |  |  |  | my $ll = $e->data; | 
| 17 | 0 | 0 |  |  |  |  | if ( $opt->clear_tags ) { | 
|  |  | 0 |  |  |  |  |  | 
| 18 | 0 |  |  |  |  |  | $ll->tags = []; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  | elsif ( $opt->untag ) { | 
| 21 | 0 |  |  |  |  |  | my %tags = map { $_ => 1 } @{ $ll->tags }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 22 | 0 |  |  |  |  |  | delete $tags{$_} for @{ $opt->untag }; | 
|  | 0 |  |  |  |  |  |  | 
| 23 | 0 |  |  |  |  |  | $ll->tags = [ sort keys %tags ]; | 
| 24 |  |  |  |  |  |  | } | 
| 25 | 0 | 0 |  |  |  |  | if ( $opt->tag ) { | 
| 26 | 0 |  |  |  |  |  | my %tags = map { $_ => 1 } @{ $ll->tags }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 27 | 0 |  |  |  |  |  | $tags{$_} = 1 for @{ $opt->tag }; | 
|  | 0 |  |  |  |  |  |  | 
| 28 | 0 |  |  |  |  |  | $ll->tags = [ sort keys %tags ]; | 
| 29 |  |  |  |  |  |  | } | 
| 30 | 0 |  |  |  |  |  | my $description = join ' ', @$args; | 
| 31 | 0 |  | 0 |  |  |  | for ( $opt->desc || '' ) { | 
| 32 | 0 |  |  |  |  |  | when ('replace_description') { | 
| 33 | 0 |  |  |  |  |  | $ll->description = [$description]; | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 0 |  |  |  |  |  | when ('add_description') { | 
| 36 | 0 |  |  |  |  |  | push @{ $ll->description }, $description; | 
|  | 0 |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | } | 
| 39 | 0 |  |  |  |  |  | $log->replace( $i, $ll ); | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  | 0 | 1 |  | sub usage_desc { '%c ' . __PACKAGE__->name . ' %o []' } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 0 |  |  | 0 | 1 |  | sub abstract { 'add details to last event' } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub options { | 
| 47 |  |  |  |  |  |  | return ( | 
| 48 |  |  |  |  |  |  | [ | 
| 49 | 0 |  |  | 0 | 0 |  | desc => hidden => { | 
| 50 |  |  |  |  |  |  | one_of => [ | 
| 51 |  |  |  |  |  |  | [ "add-description|a" => "add some descriptive text" ], | 
| 52 |  |  |  |  |  |  | [ | 
| 53 |  |  |  |  |  |  | "replace-description|r" => "replace current description" | 
| 54 |  |  |  |  |  |  | ], | 
| 55 |  |  |  |  |  |  | ] | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | ], | 
| 58 |  |  |  |  |  |  | [ "tag|t=s@",     "add tag; e.g., -t foo -t bar" ], | 
| 59 |  |  |  |  |  |  | [ "untag|u=s@",   "remove tag; e.g., -u foo -u bar" ], | 
| 60 |  |  |  |  |  |  | [ "clear-tags|c", "remove all tags" ], | 
| 61 |  |  |  |  |  |  | ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub validate { | 
| 65 | 0 |  |  | 0 | 0 |  | my ( $self, $opt, $args ) = @_; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  |  |  |  | my $has_modification = grep { $_ } @{$opt}{qw(desc tag untag clear_tags)}; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 68 | 0 | 0 |  |  |  |  | $self->usage_error('no modification specified') unless $has_modification; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 | 0 |  |  |  |  | if ( $opt->desc ) { | 
| 71 | 0 | 0 |  |  |  |  | $self->usage_error('no description provided') unless @$args; | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | 1; | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | __END__ |