| 1 | package JIRA::REST::Class::Issue::TimeTracking; | ||
| 2 | use parent qw( JIRA::REST::Class::Abstract ); | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use 5.010; | ||
| 6 | |||
| 7 | our $VERSION = '0.10'; | ||
| 8 | our $SOURCE = 'CPAN'; | ||
| 9 | ## $SOURCE = 'GitHub'; # COMMENT | ||
| 10 | # the line above will be commented out by Dist::Zilla | ||
| 11 | |||
| 12 | # ABSTRACT: A helper class for L<JIRA::REST::Class|JIRA::REST::Class> that represents the time tracking for a JIRA issue as an object. | ||
| 13 | |||
| 14 | use Contextual::Return; | ||
| 15 | |||
| 16 | sub init { | ||
| 17 | my $self = shift; | ||
| 18 | $self->SUPER::init( @_ ); | ||
| 19 | |||
| 20 | my $data = $self->issue->get( q{}, { fields => 'timetracking' } ); | ||
| 21 | $self->{data} = $data->{fields}->{timetracking}; | ||
| 22 | |||
| 23 | return; | ||
| 24 | } | ||
| 25 | |||
| 26 | #pod =accessor B<originalEstimate> | ||
| 27 | #pod | ||
| 28 | #pod Returns the original estimate as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 29 | #pod | ||
| 30 | #pod =cut | ||
| 31 | |||
| 32 | sub originalEstimate { | ||
| 33 | my $self = shift; | ||
| 34 | #<<< | ||
| 35 | return | ||
| 36 | NUM { $self->data->{originalEstimateSeconds} } | ||
| 37 | STR { $self->data->{originalEstimate} } | ||
| 38 | ; | ||
| 39 | #>>> | ||
| 40 | } | ||
| 41 | |||
| 42 | #pod =accessor B<remainingEstimate> | ||
| 43 | #pod | ||
| 44 | #pod Returns the remaining estimate as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 45 | #pod | ||
| 46 | #pod =cut | ||
| 47 | |||
| 48 | sub remainingEstimate { | ||
| 49 | my $self = shift; | ||
| 50 | #<<< | ||
| 51 | return | ||
| 52 | NUM { $self->data->{remainingEstimateSeconds} } | ||
| 53 | STR { $self->data->{remainingEstimate} } | ||
| 54 | ; | ||
| 55 | #>>> | ||
| 56 | } | ||
| 57 | |||
| 58 | #pod =accessor B<timeSpent> | ||
| 59 | #pod | ||
| 60 | #pod Returns the time spent as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 61 | #pod | ||
| 62 | #pod =cut | ||
| 63 | |||
| 64 | sub timeSpent { | ||
| 65 | my $self = shift; | ||
| 66 | #<<< | ||
| 67 | return | ||
| 68 | NUM { $self->data->{timeSpentSeconds} } | ||
| 69 | STR { $self->data->{timeSpent} } | ||
| 70 | ; | ||
| 71 | #>>> | ||
| 72 | } | ||
| 73 | |||
| 74 | #pod =method B<set_originalEstimate> | ||
| 75 | #pod | ||
| 76 | #pod Sets the original estimate to the amount of time given. Accepts any time format that JIRA uses. | ||
| 77 | #pod | ||
| 78 | #pod =cut | ||
| 79 | |||
| 80 | sub set_originalEstimate { | ||
| 81 | my $self = shift; | ||
| 82 | my $est = shift; | ||
| 83 | return $self->update( { originalEstimate => $est } ); | ||
| 84 | } | ||
| 85 | |||
| 86 | #pod =method B<set_remainingEstimate> | ||
| 87 | #pod | ||
| 88 | #pod Sets the remaining estimate to the amount of time given. Accepts any time format that JIRA uses. | ||
| 89 | #pod | ||
| 90 | #pod =cut | ||
| 91 | |||
| 92 | sub set_remainingEstimate { | ||
| 93 | my $self = shift; | ||
| 94 | my $est = shift; | ||
| 95 | return $self->update( { remainingEstimate => $est } ); | ||
| 96 | } | ||
| 97 | |||
| 98 | #pod =method B<update> | ||
| 99 | #pod | ||
| 100 | #pod Accepts a hashref of timetracking fields to update. The acceptable fields are determined by JIRA, but I think they're originalEstimate and remainingEstimate. | ||
| 101 | #pod | ||
| 102 | #pod =cut | ||
| 103 | |||
| 104 | sub update { | ||
| 105 | my $self = shift; | ||
| 106 | my $update = shift; | ||
| 107 | |||
| 108 | foreach my $key ( qw/ originalEstimate remainingEstimate / ) { | ||
| 109 | |||
| 110 | # if we're updating the key, don't change it | ||
| 111 | next if exists $update->{$key}; | ||
| 112 | |||
| 113 | # since we're not updating the key, copy the original value | ||
| 114 | # into the update, because the REST interface has an annoying | ||
| 115 | # tendency to reset those values if you don't explicitly set them | ||
| 116 | if ( defined $self->data->{$key} ) { | ||
| 117 | $update->{$key} = $self->data->{$key}; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | return $self->issue->put_field( timetracking => $update ); | ||
| 122 | } | ||
| 123 | |||
| 124 | 1; | ||
| 125 | |||
| 126 | __END__ | ||
| 127 | |||
| 128 | =pod | ||
| 129 | |||
| 130 | =encoding UTF-8 | ||
| 131 | |||
| 132 | =for :stopwords Packy Anderson Alexey Melezhik Atlassian GreenHopper JRC ScriptRunner TODO | ||
| 133 | aggregateprogress aggregatetimeestimate aggregatetimeoriginalestimate | ||
| 134 | assigneeType avatar avatarUrls completeDate displayName duedate | ||
| 135 | emailAddress endDate fieldtype fixVersions fromString genericized iconUrl | ||
| 136 | isAssigneeTypeValid issueTypes issuekeys issuelinks issuetype jira jql | ||
| 137 | lastViewed maxResults originalEstimate originalEstimateSeconds parentkey | ||
| 138 | projectId rapidViewId remainingEstimate remainingEstimateSeconds | ||
| 139 | resolutiondate sprintlist startDate subtaskIssueTypes timeSpent | ||
| 140 | timeSpentSeconds timeestimate timeoriginalestimate timespent timetracking | ||
| 141 | toString updateAuthor worklog workratio | ||
| 142 | |||
| 143 | =head1 NAME | ||
| 144 | |||
| 145 | JIRA::REST::Class::Issue::TimeTracking - A helper class for L<JIRA::REST::Class|JIRA::REST::Class> that represents the time tracking for a JIRA issue as an object. | ||
| 146 | |||
| 147 | =head1 VERSION | ||
| 148 | |||
| 149 | version 0.10 | ||
| 150 | |||
| 151 | =head1 METHODS | ||
| 152 | |||
| 153 | =head2 B<set_originalEstimate> | ||
| 154 | |||
| 155 | Sets the original estimate to the amount of time given. Accepts any time format that JIRA uses. | ||
| 156 | |||
| 157 | =head2 B<set_remainingEstimate> | ||
| 158 | |||
| 159 | Sets the remaining estimate to the amount of time given. Accepts any time format that JIRA uses. | ||
| 160 | |||
| 161 | =head2 B<update> | ||
| 162 | |||
| 163 | Accepts a hashref of timetracking fields to update. The acceptable fields are determined by JIRA, but I think they're originalEstimate and remainingEstimate. | ||
| 164 | |||
| 165 | =head1 READ-ONLY ACCESSORS | ||
| 166 | |||
| 167 | =head2 B<originalEstimate> | ||
| 168 | |||
| 169 | Returns the original estimate as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 170 | |||
| 171 | =head2 B<remainingEstimate> | ||
| 172 | |||
| 173 | Returns the remaining estimate as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 174 | |||
| 175 | =head2 B<timeSpent> | ||
| 176 | |||
| 177 | Returns the time spent as a number of seconds in numeric context, and as a w/d/h/m/s string in a string context. | ||
| 178 | |||
| 179 | =head1 RELATED CLASSES | ||
| 180 | |||
| 181 | =over 2 | ||
| 182 | |||
| 183 | =item * L<JIRA::REST::Class|JIRA::REST::Class> | ||
| 184 | |||
| 185 | =item * L<JIRA::REST::Class::Abstract|JIRA::REST::Class::Abstract> | ||
| 186 | |||
| 187 | =back | ||
| 188 | |||
| 189 | =head1 AUTHOR | ||
| 190 | |||
| 191 | Packy Anderson <packy@cpan.org> | ||
| 192 | |||
| 193 | =head1 COPYRIGHT AND LICENSE | ||
| 194 | |||
| 195 | This software is Copyright (c) 2017 by Packy Anderson. | ||
| 196 | |||
| 197 | This is free software, licensed under: | ||
| 198 | |||
| 199 | The Artistic License 2.0 (GPL Compatible) | ||
| 200 | |||
| 201 | =cut |