File Coverage

blib/lib/Reddit/Client/ModmailConversation.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 10 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 1 3 33.3
total 21 57 36.8


line stmt bran cond sub pod time code
1             package Reddit::Client::ModmailConversation;
2 5     5   32 use strict;
  5         18  
  5         140  
3 5     5   26 use warnings;
  5         12  
  5         129  
4 5     5   27 use Carp;
  5         11  
  5         358  
5              
6             require Reddit::Client::Thing;
7 5     5   34 use base qw/Reddit::Client::Thing/; # base doesn't require. use parent does
  5         10  
  5         733  
8              
9             # what will happpen if we use Thing as a parent but don't use fields here? Proly
10             # those fields cause errs. # Just use them, no sense fucking with it now
11             # id
12 5         29 use fields qw/
13             authors
14             isAuto
15             isHighlighted
16             isInternal
17             isRepliable
18             lastModUpdate
19             lastUnread
20             lastUpdated
21             lastUserUpdate
22             numMessages
23             objIds
24             owner
25             participant
26             state
27             subject
28              
29             messages
30             modActions
31 5     5   35 /;
  5         20  
32              
33             # no type, apparently. None listed in docs. Message is t4, but no indication
34             # these are Messages
35             sub new {
36 0     0 1   my ($class, $reddit, $conversation, $messages, $modActions) = @_;
37 0           my $data = $conversation;
38 0 0         if (ref $data eq 'HASH') {
39             # if we put messages here, we have to use fuckery to make it come after
40             # isObj, because that must exist first. might as well just call our
41             # thing after.
42             #$data->{messages} = $messages if $messages;
43 0 0         $data->{modActions} = $modActions if $modActions;
44             } else {
45 0           die "Expected a hash reference for arg 2\n";
46             }
47 0           my $this = $class->SUPER::new($reddit, $data);
48 0 0         $this->set_messages($messages) if $messages;
49              
50 0           return $this;
51             }
52              
53             # Expects hash reference containing hash references of arbitrary keys
54             # (keys are message IDs)
55             sub set_messages {
56 0     0 0   my ($this, $msgdat) = @_;
57              
58             # this should create an array of ModmailMessages out of $messages using the
59             # order in objIds. objIds must be set first
60              
61 0           my $messages = [];
62              
63 0 0 0       if (ref $this->{objIds} eq 'ARRAY' and ref $msgdat eq 'HASH') {
64 0           for my $o ( @{$this->{objIds}}) {
  0            
65 0 0         if ($o->{key} eq 'messages') {
66 0           push @$messages, new Reddit::Client::ModmailMessage( $this->{session}, $msgdat->{$o->{id}} );
67             }
68             }
69 0           $this->{messages} = $messages;
70             }
71              
72             }
73              
74             sub archive {
75 0     0 0   my $this = shift;
76 0           return $this->{session}->modmail_action('archive', $this->{id});
77             }
78