App-JobLog
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/JobLog/Log/Event.pm view on Meta::CPAN
package App::JobLog::Log::Event;
$App::JobLog::Log::Event::VERSION = '1.042';
# ABSTRACT: basically adds an end time to App::JobLog::Log::Line events
use parent qw(App::JobLog::Log::Note);
use Modern::Perl;
use Class::Autouse qw{DateTime};
use autouse 'App::JobLog::Time' => qw(now);
use autouse 'Carp' => qw(carp);
# for debugging
use overload '""' => sub {
$_[0]->data->to_string . '-->'
. ( $_[0]->is_closed ? $_[0]->end : 'ongoing' );
};
sub clone {
my ($self) = @_;
my $clone = $self->new( $self->data->clone );
$clone->end = $self->end->clone unless $self->is_open;
return $clone;
}
sub overlap {
my ( $self, $start, $end ) = @_;
# if this falls entirely within interval, return this
my $c1 = DateTime->compare( $start, $self->start ) || 0;
my $c2 = DateTime->compare( $end, $self->end ) || 0;
if ( $c1 <= 0 && $c2 >= 0 ) {
return $self;
}
return if $self->start >= $end || $start >= $self->end;
my $s = $c1 < 0 ? $self->start : $start;
my $e = $c2 < 0 ? $end : $self->end;
my $clone = $self->clone;
$clone->start = $s;
$clone->end = $e;
return $clone;
}
sub end : lvalue {
$_[0]->{end};
}
sub cmp {
my ( $self, $other ) = @_;
my $comparison = $self->SUPER::cmp($other);
unless ($comparison) {
if ( $other->isa(__PACKAGE__) ) {
if ( $self->is_closed ) {
if ( $other->is_closed ) {
return DateTime->compare( $self->end, $other->end );
}
else {
return 1;
}
}
elsif ( $other->is_closed ) {
return -1;
}
else {
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.615 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )