File Coverage

blib/lib/WebService/SlimTimer/TimeEntry.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 38 38 100.0


line stmt bran cond sub pod time code
1             # PODNAME: WebService::SlimTimer::TimeEntry
2             #
3             # ABSTRACT: Represents a time entry record in SlimTimer.
4              
5 3     3   219390 use MooseX::Declare;
  3         2776910  
  3         30  
6              
7             class WebService::SlimTimer::TimeEntry
8 3     3   55932 {
  3     3   10  
  3     3   138  
  3     3   41130  
  3         7  
  3         28  
  3         25484  
  3         8  
  3         37  
  3         337  
9              
10              
11 3     3   161 use strict;
  3         6  
  3         101  
12 3     3   18 use warnings;
  3         5  
  3         134  
13              
14 3     3   50 use MooseX::Types::Moose qw(Bool Int Maybe Str);
  3         6  
  3         40  
15 3     3   23772 use WebService::SlimTimer::Types qw(TimeStamp);
  3         2269  
  3         25  
16              
17 3     3   1120756 method BUILDARGS(ClassName $class: HashRef $desc) {
18             # We use a different (shorter) name for one of the attributes compared to
19             # the YAML format, translate it on the fly.
20             $desc->{duration} = delete $desc->{duration_in_seconds};
21              
22             # We also want to extract the associated task id and name from the nested
23             # task hash if present (otherwise task_id must be specified explicitly).
24             if ( exists $desc->{'task'} ) {
25             $desc->{task_id} = $desc->{task}->{id};
26             $desc->{task_name} = $desc->{task}->{name};
27             }
28              
29             return $desc;
30             }
31              
32             has id => ( is => 'ro', isa => Int, required => 1 );
33             has task_id => ( is => 'ro', isa => Int, required => 1 );
34             has task_name => ( is => 'ro', isa => Str );
35             has start_time => ( is => 'ro', isa => TimeStamp, required => 1, coerce => 1 );
36             has end_time => ( is => 'ro', isa => TimeStamp, required => 1, coerce => 1 );
37             has created_at => ( is => 'ro', isa => TimeStamp, required => 1, coerce => 1 );
38             has updated_at => ( is => 'ro', isa => TimeStamp, required => 1, coerce => 1 );
39             has duration => ( is => 'ro', isa => Int, required => 1 );
40             has comments => ( is => 'ro', isa => Maybe[Str] );
41             has in_progress => ( is => 'ro', isa => Bool, required => 1 );
42              
43             # TODO: Add tags.
44              
45 3     3   8094 }
46              
47             __END__
48             =pod
49              
50             =head1 NAME
51              
52             WebService::SlimTimer::TimeEntry - Represents a time entry record in SlimTimer.
53              
54             =head1 VERSION
55              
56             version 0.005
57              
58             =head1 SYNOPSIS
59              
60             The objects of this class repesent a single entry spent on some SlimTimer
61             task. Just as L<WebService::SlimTimer::Task> objects, they are never created
62             directly but are returned by L<WebService::SlimTimer> methods such as
63             C<list_entries()> or C<get_entry()>.
64              
65             my @entries = $st->list_entries(start => ..., end => ...);
66             my $total = 0;
67             for my $e (@entries) {
68             $total += $e->duration;
69             }
70              
71             print "Total time spent during the given interval $total seconds.\n";
72              
73             =head1 ATTRIBUTES
74              
75             =head2 id
76              
77             The unique numeric id of the entry.
78              
79             =head2 task_id
80              
81             The numeric id of the associated task.
82              
83             =head2 task_name
84              
85             The name of the associated task, provided as a convenience to avoid the need
86             for calling L<WebService::SlimTimer/get_task> just to retrieve it.
87              
88             =head2 start_time
89              
90             The time when the entry started.
91              
92             =head2 end_time
93              
94             The time when the entry ended.
95              
96             =head2 duration
97              
98             Duration of the entry in seconds.
99              
100             =head2 created_at
101              
102             The time when the entry itself was created.
103              
104             =head2 updated_at
105              
106             The time when the entry was last modified.
107              
108             =head1 SEE ALSO
109              
110             L<WebService::SlimTimer>
111              
112             =head1 AUTHOR
113              
114             Vadim Zeitlin <vz-cpan@zeitlins.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2011 by Vadim Zeitlin.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut
124