App-JobLog

 view release on metacpan or  search on metacpan

lib/App/JobLog/Log/Note.pm  view on Meta::CPAN

package App::JobLog::Log::Note;
$App::JobLog::Log::Note::VERSION = '1.042';
# ABSTRACT: timestamped annotation in log


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;
};
use overload 'bool' => sub { 1 };


sub new {
   my ( $class, $logline ) = @_;
   $class = ref $class || $class;
   my $self = bless { log => $logline }, $class;
   return $self;
}


sub clone {
   my ($self) = @_;
   my $clone = $self->new( $self->data->clone );
   return $clone;
}


sub data {
   $_[0]->{log};
}


sub start : lvalue {
   $_[0]->data->time;
}


sub tags : lvalue {
   $_[0]->data->{tags};
}


sub tagged { !!@{ $_[0]->tags } }


sub tag_list { @{ $_[0]->tags } }


sub describe {
   my ($self) = @_;
   join '; ', @{ $self->data->description };
}


sub exists_tag {
   my ( $self, @tags ) = @_;
   $self->data->exists_tag(@tags);
}


sub all_tags {
   my ( $self, @tags ) = @_;
   $self->data->all_tags(@tags);
}


sub cmp {
   my ( $self, $other ) = @_;
   carp 'argument must also be time' unless $other->isa(__PACKAGE__);

   # defer to subclass sort order if other is a subclass and self isn't
   return -$other->cmp($self)
     if ref $self eq __PACKAGE__ && ref $other ne __PACKAGE__;

   return DateTime->compare( $self->start, $other->start );
}


sub split_days {
   return $_[0];
}


sub intersects {
   my ( $self, $other ) = @_;
   if ( $other->can('end') ) {
      return $self->start >= $other->start && $self->start < $other->end;
   }
   return $self->start == $other->start;
}


sub is_note {
  shift->{log}->is_note
}


sub is_open { 0 }

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::JobLog::Log::Note - timestamped annotation in log

=head1 VERSION

version 1.042

=head1 DESCRIPTION

A wrapper for a log line that represents a timestamped and optionally tagged note.

=head1 METHODS

=head2 new

Basic constructor. Expects single L<App::JobLog::Log::Line> argument. Can be called on
instance or class.

=head2 clone

Create a duplicate of this event.

=head2 data

Returns L<App::JobLog::Log::Line> object on which this event is based.

=head2 start



( run in 0.745 second using v1.01-cache-2.11-cpan-39bf76dae61 )