line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Snoo::Subreddit; |
2
|
5
|
|
|
5
|
|
206181
|
use Moo; |
|
5
|
|
|
|
|
55615
|
|
|
5
|
|
|
|
|
30
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
extends 'Mojo::Snoo::Base'; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
9261
|
use Mojo::Collection; |
|
5
|
|
|
|
|
12456
|
|
|
5
|
|
|
|
|
186
|
|
7
|
5
|
|
|
5
|
|
2762
|
use Mojo::Snoo::Link; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
184
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
33
|
use constant FIELD => 'name'; |
|
5
|
|
|
|
|
66
|
|
|
5
|
|
|
|
|
6476
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has name => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => sub { |
14
|
|
|
|
|
|
|
die "Subreddit needs a name!" unless $_[0]; |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
required => 1 |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
5
|
100
|
|
5
|
0
|
11426
|
sub BUILDARGS { shift->SUPER::BUILDARGS(@_ == 1 ? (name => shift) : @_) } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub mods { |
22
|
1
|
|
|
1
|
1
|
18
|
my $self = shift; |
23
|
1
|
|
|
|
|
7
|
my $path = '/r/' . $self->name . '/about/moderators'; |
24
|
1
|
|
|
|
|
8
|
my $res = $self->_do_request('GET', $path); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Do we have a callback? |
27
|
1
|
50
|
|
|
|
1215
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
28
|
1
|
50
|
|
|
|
6
|
$res->$cb if $cb; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
469
|
my @mods = @{$res->json->{data}{children}}; |
|
1
|
|
|
|
|
9
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# FIXME should we return User objects instead? or combined? |
33
|
1
|
|
|
|
|
473
|
my @collection; |
34
|
1
|
|
|
|
|
3
|
for my $child (@mods) { |
35
|
2
|
|
|
|
|
10
|
my $pkg = 'Mojo::Snoo::Subreddit::Mods::' . $self->name . '::' . $child->{name}; |
36
|
2
|
|
|
|
|
11
|
push @collection, $self->_monkey_patch($pkg, $child); |
37
|
|
|
|
|
|
|
} |
38
|
1
|
|
|
|
|
9
|
Mojo::Collection->new(@collection); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub about { |
42
|
1
|
|
|
1
|
1
|
17
|
my $self = shift; |
43
|
1
|
|
|
|
|
7
|
my $path = '/r/' . $self->name . '/about'; |
44
|
1
|
|
|
|
|
8
|
my $res = $self->_do_request('GET', $path); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Do we have a callback? |
47
|
1
|
50
|
|
|
|
1228
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
48
|
1
|
50
|
|
|
|
8
|
$res->$cb if $cb; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
517
|
my $pkg = 'Mojo::Snoo::Subreddit::About::' . $self->name; |
51
|
1
|
|
|
|
|
9
|
$self->_monkey_patch($pkg, $res->json->{data}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _toggle_subscribe { |
55
|
0
|
|
|
0
|
|
0
|
my ($self, $action) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Calling $self->about feels like a hack |
58
|
|
|
|
|
|
|
# However, a request is needed to get the t5_ name of a subreddit |
59
|
0
|
|
|
|
|
0
|
my %params = (action => $action, sr => $self->about->name); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $res = $self->_do_request('POST', '/api/subscribe', %params); |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
64
|
0
|
0
|
|
|
|
0
|
$res->$cb if $cb; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
0
|
sub subscribe { shift->_toggle_subscribe('sub', @_) } |
68
|
0
|
|
|
0
|
1
|
0
|
sub unsubscribe { shift->_toggle_subscribe('unsub', @_) } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _submit { |
71
|
0
|
0
|
|
0
|
|
0
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
72
|
0
|
0
|
|
|
|
0
|
my $params = ref $_[-1] eq 'HASH' ? pop : {}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
my ($self, $kind, $title, $content) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
my $post_type = $kind eq 'self' ? 'text' : 'url'; |
77
|
0
|
|
|
|
|
0
|
$params->{$post_type} = $content; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
0
|
|
|
0
|
$params->{title} //= $title // ''; |
|
|
|
0
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
$params->{sr} = $self->name; |
81
|
0
|
|
|
|
|
0
|
$params->{api_type} = 'json'; |
82
|
0
|
|
|
|
|
0
|
$params->{kind} = $kind; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $res = $self->_do_request('POST', '/api/submit', %$params); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
$res->$cb if $cb; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
0
|
sub submit_link { shift->_submit('link', @_) } |
90
|
0
|
|
|
0
|
0
|
0
|
sub submit_text { shift->_submit('self', @_) } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _get_links { |
93
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
5
|
my $path = '/r/' . $self->name; |
96
|
|
|
|
|
|
|
|
97
|
1
|
50
|
|
|
|
4
|
if (my $sort = shift) { |
98
|
0
|
|
|
|
|
0
|
$path .= "/$sort"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Do we have a callback? |
102
|
1
|
50
|
|
|
|
4
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Did we receive extra endpoint parameters? |
105
|
1
|
50
|
|
|
|
4
|
my $params = ref $_[-1] eq 'HASH' ? pop : {}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Define these from special method calls unless |
108
|
|
|
|
|
|
|
# user has already done so via the params hash |
109
|
1
|
|
|
|
|
2
|
my $t = shift; |
110
|
1
|
|
|
|
|
1
|
my $limit = shift; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
0
|
|
|
6
|
$params->{t} ||= $t || ''; |
|
|
|
33
|
|
|
|
|
113
|
1
|
|
50
|
|
|
8
|
$params->{limit} ||= $limit || ''; |
|
|
|
33
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
9
|
my $res = $self->_do_request('GET', $path, %$params); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# run callback |
118
|
1
|
50
|
|
|
|
1245
|
$res->$cb if $cb; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my @children = |
121
|
2
|
50
|
|
|
|
551
|
map { $_->{kind} eq 't3' ? $_->{data} : () } # |
122
|
1
|
|
|
|
|
334
|
@{$res->json->{data}{children}}; |
|
1
|
|
|
|
|
9
|
|
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
3
|
my %args = map { $_ => $self->$_ } ( |
|
4
|
|
|
|
|
27
|
|
125
|
|
|
|
|
|
|
qw( |
126
|
|
|
|
|
|
|
username |
127
|
|
|
|
|
|
|
password |
128
|
|
|
|
|
|
|
client_id |
129
|
|
|
|
|
|
|
client_secret |
130
|
|
|
|
|
|
|
) |
131
|
|
|
|
|
|
|
); |
132
|
1
|
|
|
|
|
3
|
Mojo::Collection->new(map { Mojo::Snoo::Link->new(%args, %$_) } @children); |
|
2
|
|
|
|
|
299
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
1
|
1
|
20
|
sub links { shift->_get_links('' , '' , @_) } |
136
|
0
|
|
|
0
|
1
|
|
sub links_new { shift->_get_links('new' , '' , @_) } |
137
|
0
|
|
|
0
|
1
|
|
sub links_rising { shift->_get_links('rising' , '' , @_) } |
138
|
0
|
|
|
0
|
1
|
|
sub links_contro { shift->_get_links('controversial', '' , @_) } |
139
|
0
|
|
|
0
|
1
|
|
sub links_contro_week { shift->_get_links('controversial', 'week' , @_) } |
140
|
0
|
|
|
0
|
1
|
|
sub links_contro_month { shift->_get_links('controversial', 'month', @_) } |
141
|
0
|
|
|
0
|
1
|
|
sub links_contro_year { shift->_get_links('controversial', 'year' , @_) } |
142
|
0
|
|
|
0
|
1
|
|
sub links_contro_all { shift->_get_links('controversial', 'all' , @_) } |
143
|
0
|
|
|
0
|
1
|
|
sub links_top { shift->_get_links('top' , '' , @_) } |
144
|
0
|
|
|
0
|
1
|
|
sub links_top_week { shift->_get_links('top' , 'week' , @_) } |
145
|
0
|
|
|
0
|
1
|
|
sub links_top_month { shift->_get_links('top' , 'month', @_) } |
146
|
0
|
|
|
0
|
1
|
|
sub links_top_year { shift->_get_links('top' , 'year' , @_) } |
147
|
0
|
|
|
0
|
1
|
|
sub links_top_all { shift->_get_links('top' , 'all' , @_) } |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |