File Coverage

blib/lib/WebService/30Boxes/API/Todo.pm
Criterion Covered Total %
statement 9 45 20.0
branch 0 18 0.0
condition n/a
subroutine 3 12 25.0
pod 9 9 100.0
total 21 84 25.0


line stmt bran cond sub pod time code
1             package WebService::30Boxes::API::Todo;
2              
3 1     1   5 use strict;
  1         1  
  1         38  
4 1     1   5 use warnings;
  1         2  
  1         31  
5 1     1   4 use Carp qw/croak/;
  1         2  
  1         1000  
6              
7             our $VERSION = '1.05';
8              
9             sub new {
10 0     0 1   my ($class, $result, $success, $error_code, $error_message) = @_;
11 0 0         croak "The response from 30Boxes was not a success" unless $result->{'success'};
12              
13             #%{$result->{'_xml'}->{'todoList'}->{'todo'}} is a hash with todo ids as keys
14 0           my $self = { todo => $result->{'_xml'}->{'todoList'}->{'todo'},
15 0           todoIds => [sort keys %{$result->{'_xml'}->{'todoList'}->{'todo'}}],
16             todoIndex => -1,
17             success => $success,
18             error_code => $error_code,
19             error_message => $error_message,
20             };
21 0           bless $self, $class;
22 0           return $self;
23             }
24              
25             #return an array of todo ids
26             sub get_todoIds {
27 0     0 1   my ($self) = @_;
28 0           return @{$self->{'todoIds'}};
  0            
29             }
30              
31             #return a reference to an array of todo ids
32             sub get_ref_todoIds {
33 0     0 1   my ($self) = @_;
34 0           return $self->{'todoIds'};
35             }
36              
37             #advance the todoIndex
38             sub nextTodoId {
39 0     0 1   my ($self) = @_;
40 0 0         return 0 if $self->{'todoIndex'} == scalar(@{$self->{'todoIds'}}) - 1;
  0            
41 0           return $self->{'todoIds'}->[$self->{'todoIndex'}++];
42             }
43            
44             #returns a list of tags
45             sub get_tags {
46 0     0 1   my ($self, $todoId) = @_;
47 0 0         $todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
48 0           my $temp = $self->{'todo'}->{$todoId}->{'tags'};
49 0 0         return "" if ref($temp);#it's a hash if empty
50 0           $temp =~ s/\s+/ /;
51 0           return split(/ /, $temp);
52             }
53              
54             #gets the title for the todos
55             sub get_title {
56 0     0 1   my ($self, $todoId) = @_;
57 0 0         $todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
58 0           return $self->{'todo'}->{$todoId}->{'summary'};
59             }
60              
61             #get if the the todo is marked as done
62             #returns 1 if yes, 0 if not
63             sub isDone {
64 0     0 1   my ($self, $todoId) = @_;
65 0 0         $todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
66 0           return $self->{'todo'}->{$todoId}->{'done'};
67             }
68              
69             #returns the position of the todo in the list
70             sub get_position {
71 0     0 1   my ($self, $todoId) = @_;
72 0 0         $todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
73 0           return $self->{'todo'}->{$todoId}->{'position'};
74             }
75              
76             sub get_externalUID {
77 0     0 1   my ($self, $todoId) = @_;
78 0 0         $todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
79 0           my $temp = $self->{'todo'}->{$todoId}->{'externalUID'};
80 0 0         return "" if ref($temp);#it's a hash if empty
81 0           $temp =~ s/\s+/ /;
82 0           return split(/ /, $temp);
83             }
84              
85              
86             1;
87             __END__