App-JobLog
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/JobLog/Command/add.pm view on Meta::CPAN
package App::JobLog::Command::add;
$App::JobLog::Command::add::VERSION = '1.042';
# ABSTRACT: log an event
use App::JobLog -command;
use Modern::Perl;
use autouse 'Getopt::Long::Descriptive' => qw(prog_name);
use autouse 'App::JobLog::Time' => qw(now);
use Class::Autouse qw(App::JobLog::Log);
sub execute {
my ( $self, $opt, $args ) = @_;
my $tags = $opt->tag;
unless ($tags) {
$tags = [] if $opt->clear_tags;
}
my $log = App::JobLog::Log->new;
my ($last) = $log->last_event;
my $is_ongoing = $last && $last->is_open;
$log->append_event(
$tags ? ( tags => $tags ) : (),
description => [ join ' ', @$args ],
time => now
);
if ( $is_ongoing && _different_day( $last->start, now ) ) {
say 'Event spans midnight. Perhaps you failed to close the last event.';
}
}
sub _different_day {
my ( $d1, $d2 ) = @_;
return !( $d1->year == $d2->year
&& $d1->month == $d2->month
&& $d1->day == $d2->day );
}
sub usage_desc { '%c ' . __PACKAGE__->name . ' <description of event>' }
sub abstract { 'log an event' }
sub full_description {
<<END;
Log an event. E.g.,
@{[prog_name($0)]} @{[__PACKAGE__->name]} munging the widget
All arguments that are not parameter values are concatenated as a description
of the event. Logging an event simultaneously marks the end of the previous
event. Events may be tagged to mark such things as client, grant, or
project.
END
}
sub options {
return (
[
'tag|t=s@',
'tag the event; multiple tags are acceptable; e.g., -t foo -t bar -t quux',
],
[
'clear-tags|T',
'inherit no tags from preceding event; '
. 'this is equivalent to -t ""; '
. 'this option has no effect if any tag is specified',
],
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.685 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )