| 1 | package Reddit::Client::Comment; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | require Reddit::Client::VotableThing; | |||||||||||||||||||||||||||
| 8 | # comments don't have over_18 and is_self, do they? | ||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use base qw/Reddit::Client::VotableThing/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use fields qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | approved_by | ||||||||||||||||||||||||||||
| 12 | author | ||||||||||||||||||||||||||||
| 13 | author_flair_css_class | ||||||||||||||||||||||||||||
| 14 | author_flair_text | ||||||||||||||||||||||||||||
| 15 | banned_by | ||||||||||||||||||||||||||||
| 16 | body | ||||||||||||||||||||||||||||
| 17 | body_html | ||||||||||||||||||||||||||||
| 18 | can_mod_post | ||||||||||||||||||||||||||||
| 19 | clicked | ||||||||||||||||||||||||||||
| 20 | created | ||||||||||||||||||||||||||||
| 21 | created_utc | ||||||||||||||||||||||||||||
| 22 | domain | ||||||||||||||||||||||||||||
| 23 | hidden | ||||||||||||||||||||||||||||
| 24 | is_self | ||||||||||||||||||||||||||||
| 25 | link_author | ||||||||||||||||||||||||||||
| 26 | link_id | ||||||||||||||||||||||||||||
| 27 | link_permalink | ||||||||||||||||||||||||||||
| 28 | link_title | ||||||||||||||||||||||||||||
| 29 | link_url | ||||||||||||||||||||||||||||
| 30 | locked | ||||||||||||||||||||||||||||
| 31 | media_embed | ||||||||||||||||||||||||||||
| 32 | mod_reports | ||||||||||||||||||||||||||||
| 33 | more | ||||||||||||||||||||||||||||
| 34 | num_comments | ||||||||||||||||||||||||||||
| 35 | num_reports | ||||||||||||||||||||||||||||
| 36 | over_18 | ||||||||||||||||||||||||||||
| 37 | parent_id | ||||||||||||||||||||||||||||
| 38 | permalink | ||||||||||||||||||||||||||||
| 39 | quarantine | ||||||||||||||||||||||||||||
| 40 | removed | ||||||||||||||||||||||||||||
| 41 | replies | ||||||||||||||||||||||||||||
| 42 | saved | ||||||||||||||||||||||||||||
| 43 | selftext | ||||||||||||||||||||||||||||
| 44 | selftext_html | ||||||||||||||||||||||||||||
| 45 | spam | ||||||||||||||||||||||||||||
| 46 | stickied | ||||||||||||||||||||||||||||
| 47 | subreddit | ||||||||||||||||||||||||||||
| 48 | subreddit_id | ||||||||||||||||||||||||||||
| 49 | thumbnail | ||||||||||||||||||||||||||||
| 50 | title | ||||||||||||||||||||||||||||
| 51 | user_reports | ||||||||||||||||||||||||||||
| 52 | 5 | /; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | ▶ | use constant type => "t1"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | # This is called by the magic in Thing.pm on creation | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub set_replies { | ||||||||||||||||||||||||||
|
Subroutine
set_replies: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (ref $value && exists $value->{data}{children}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and exists $value->{"data"}{"children"}
MC/DC0%0/2
ref $value and exists $value->{"data"}{"children"}
ref $value
exists $value->{"data"}{"children"}
Truth table0%0/3
A and B
A= ref $valueB= exists $value->{"data"}{"children"}
| |||||||||||||||||||||||||||||
| 59 | 0 | my $comments = $value->{data}{children}; | |||||||||||||||||||||||||||
| 60 | 0 | my $return = []; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | for my $cmt (@$comments) { | |||||||||||||||||||||||||||
| 63 | # 'kind' is on same level as 'data' | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($cmt->{kind} eq 't1') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 65 | 0 | push @$return, Reddit::Client::Comment->new($self->{session}, $cmt->{data}); | |||||||||||||||||||||||||||
| 66 | } elsif ($cmt->{kind} eq 'more') { | ||||||||||||||||||||||||||||
| 67 | 0 | my $more = Reddit::Client::MoreComments->new($self->{session}, $cmt->{data}); | |||||||||||||||||||||||||||
| 68 | 0 | $more->{link_id} = $self->{link_id}; | |||||||||||||||||||||||||||
| 69 | 0 | $self->{more} = $more->{children}; | |||||||||||||||||||||||||||
| 70 | 0 | push @$return, $more; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $self->{replies} = $return; | |||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||
| 76 | 0 | $self->{replies} = []; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | # need fix this | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub get_collapsed_comments { | ||||||||||||||||||||||||||
|
Subroutine
get_collapsed_comments: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ($self, %param) = @_; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | return undef if !$self->{more} or ref $self->{more} ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->{"more"} or ref $self->{"more"} ne "ARRAY"
MC/DC0%0/2
not $self->{"more"} or ref $self->{"more"} ne "ARRAY"
not $self->{"more"}
ref $self->{"more"} ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not $self->{"more"}B= ref $self->{"more"} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my %data = ( | ||||||||||||||||||||||||||||
| 85 | link_id => $self->{link_id}, | ||||||||||||||||||||||||||||
| 86 | children => $self->{more}, | ||||||||||||||||||||||||||||
| 87 | 0 | ); | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | $data{sort} = $param{sort} if $param{sort}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $data{id} = $param{id} if $param{id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return $self->{session}->get_collapsed_comments( %data ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub reply { | ||||||||||||||||||||||||||
|
Subroutine
reply: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 96 | 0 | my $cmtid = $self->{session}->submit_comment(parent_id=>$self->{name}, text=>$text); | |||||||||||||||||||||||||||
| 97 | 0 | return $cmtid; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub remove { | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 0 | return $self->{session}->remove($self->{name}); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub spam { | ||||||||||||||||||||||||||
|
Subroutine
spam: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | return $self->{session}->spam($self->{name}); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub approve { | ||||||||||||||||||||||||||
|
Subroutine
approve: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 0 | return $self->{session}->approve($self->{name}); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub ignore_reports { | ||||||||||||||||||||||||||
|
Subroutine
ignore_reports: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 113 | 0 | return $self->{session}->ignore_reports($self->{name}); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub edit { | ||||||||||||||||||||||||||
|
Subroutine
edit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | my $cmtid = $self->{session}->edit($self->{name}, $text); | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | $self->{body} = $text if $cmtid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | return $cmtid; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 0 | my $cmtid = $self->{session}->delete($self->{name}); | |||||||||||||||||||||||||||
| 124 | 0 | return $cmtid; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub get_permalink { # deprecated. Duplicated instead of calling get_web_url | ||||||||||||||||||||||||||
|
Subroutine
get_permalink: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; # because this may (and probably will) change someday | |||||||||||||||||||||||||||
| 128 | return $self->{session}->get_origin().$self->{permalink} | ||||||||||||||||||||||||||||
| 129 | 0 | } | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub get_web_url { | ||||||||||||||||||||||||||
|
Subroutine
get_web_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | return $self->{session}->get_origin().$self->{permalink} | ||||||||||||||||||||||||||||
| 133 | 0 | } | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub get_children { | ||||||||||||||||||||||||||
|
Subroutine
get_children: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | 0 | my $cmts = $self->{session}->get_comments(permalink=>$self->{permalink}); | |||||||||||||||||||||||||||
| 137 | 0 | $self->{replies} = $$cmts[0]->{replies}; # populate this comment's replies | |||||||||||||||||||||||||||
| 138 | 0 | return $$cmts[0]->{replies}; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub get_comments { | ||||||||||||||||||||||||||
|
Subroutine
get_comments: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | 0 | my $cmts = $self->{session}->get_comments(permalink=>$self->{permalink}); | |||||||||||||||||||||||||||
| 143 | 0 | $self->{replies} = $$cmts[0]->{replies}; # populate this comment's replies | |||||||||||||||||||||||||||
| 144 | 0 | return $cmts; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub has_collapsed_children { | ||||||||||||||||||||||||||
|
Subroutine
has_collapsed_children: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | return $self->{more} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub replies { | ||||||||||||||||||||||||||
|
Subroutine
replies: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | return shift->{replies}; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 5 | 1; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||