App-JobLog
view release on metacpan or search on metacpan
lib/App/JobLog/Log/Line.pm view on Meta::CPAN
}
elsif ( $self->is_comment ) {
return '# ' . $self->comment;
}
}
sub time_stamp {
my ( $self, $time ) = @_;
$time ||= $self->time;
return sprintf '%d %2s %2s %2s %2s %2s', $time->year, $time->month,
$time->day, $time->hour,
$time->minute, $time->second;
}
# a bunch of attributes, here for convenience
sub text : lvalue {
$_[0]->{text};
}
sub tags : lvalue {
$_[0]->{tags};
}
sub comment : lvalue {
$_[0]->{comment};
}
sub time : lvalue {
$_[0]->{time};
}
sub description : lvalue {
$_[0]->{description};
}
# a bunch of tests
sub is_malformed { exists $_[0]->{malformed} }
sub is_beginning { exists $_[0]->{tags} }
sub is_end { $_[0]->{done} }
sub is_note { $_[0]->{note} }
sub is_event { $_[0]->{time} }
sub is_endpoint { $_[0]->{time} && !$_[0]->{note} }
sub is_comment { exists $_[0]->{comment} }
sub tags_unspecified { $_[0]->{tags_unspecified} }
sub is_blank {
!( $_[0]->is_malformed || $_[0]->is_comment || $_[0]->is_event );
}
# some useful methods
sub comment_out {
my ($self) = @_;
my $text = $self->to_string;
delete $self->{$_} for keys %$self;
$self->{comment} = $text;
return $self;
}
sub all_tags {
my ( $self, @tags ) = @_;
return unless $self->tags;
my %tags = map { $_ => 1 } @{ $self->{tags} };
for my $tag (@tags) {
return unless $tags{$tag};
}
return 1;
}
sub exists_tag {
my ( $self, @tags ) = @_;
return unless $self->tags;
my %tags = map { $_ => 1 } @{ $self->{tags} };
for my $tag (@tags) {
return 1 if $tags{$tag};
}
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::JobLog::Log::Line - encapsulates one line of log text
=head1 VERSION
version 1.042
lib/App/JobLog/Log/Line.pm view on Meta::CPAN
For parsing a line in an existing log. Expects string to parse as an argument.
=head2 clone
Produces an object semantically identical to that on which it was invoked but
stored without shared references so changes to the latter will not effect the former.
=head2 to_string
Serializes object to the string that would represent it in a log.
=head2 time_stamp
Represents optional L<DateTime> object in the format used in the log. If no
argument is provided, the timestamp of the line itself is returned.
=head2 text
Accessor to text attribute of line, if any. Should only be defined for well formed
log lines. Is lvalue.
=head2 tags
Accessor to array reference containing tags, if any. Is lvalue.
=head2 comment
Accessor to comment value, if any. Should only be defined for comment lines. Is lvalue.
=head2 time
Accessor to time value, if any. Should only be defined for event lines. Lvalue.
=head2 description
Accessor to reference to description list. Should only be defined for lines describing the
beginning of an event. Lvalue.
=head2
Whether lines is malformed.
=head2 is_beginning
Whether line describes the beginning of an event.
=head2 is_end
Whether line only defines the end of an event.
=head2 is_note
Whether the line is a note rather than a terminus of an event or
a comment or blank line.
=head2 is_event
Whether line has a time stamp.
=head2 is_endpoint
Whether the line has a timestamp marking the beginning or end of a logged
interval.
=head2 is_comment
Whether line represents a comment in the log.
=head2 tags_unspecified
Whether object was constructed from a hash of values that contained no C<tags> key.
=head2 is_blank
Whether object represents a blank line in the log.
=head2 comment_out
Convert this into a comment line.
=head2 all_tags
Expects list of tags. Returns whether all tags in list are present in object.
=head2 exists_tag
Expects list of tags. Returns whether any member of list is among tags of object.
=head1 AUTHOR
David F. Houghton <dfhoughton@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by David F. Houghton.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 0.900 second using v1.01-cache-2.11-cpan-d8267643d1d )